From 1f12da3d049527f838ab21c042b8f18e1977af49 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 25 Mar 2019 13:27:56 +0000 Subject: [PATCH] Migrate existing platform admin services to not be counted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a service has been created by someone on our team, it’s probably a test service, which shouldn’t be included in the count of live services. This commit adds a migration to do this for existing services. --- .../versions/0283_platform_admin_not_live.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 migrations/versions/0283_platform_admin_not_live.py diff --git a/migrations/versions/0283_platform_admin_not_live.py b/migrations/versions/0283_platform_admin_not_live.py new file mode 100644 index 000000000..668ef8b43 --- /dev/null +++ b/migrations/versions/0283_platform_admin_not_live.py @@ -0,0 +1,35 @@ +"""empty message + +Revision ID: 0283_platform_admin_not_live +Revises: 0282_add_count_as_live +Create Date: 2016-10-25 17:37:27.660723 + +""" + +# revision identifiers, used by Alembic. +revision = '0283_platform_admin_not_live' +down_revision = '0282_add_count_as_live' + +from alembic import op +import sqlalchemy as sa + + +STATEMENT = """ + UPDATE + services + SET + count_as_live = {count_as_live} + FROM + users + WHERE + services.created_by_id = users.id and + users.platform_admin is true + ; +""" + + +def upgrade(): + op.execute(STATEMENT.format(count_as_live='false')) + +def downgrade(): + op.execute(STATEMENT.format(count_as_live='true'))