From 853314efe9b72dfdcb2944bfbb74a525da7f7e3c Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 25 Mar 2019 17:31:52 +0000 Subject: [PATCH] Retry making services created by platform admin users not counted in the list of live services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous migration didn’t work because the `created_by_id` column in services references the user who created the _version_ of the service, not who created the service originally. This commit runs another migration to wipe all the data, and replace it using an operation that looks at the first version of the service in the history table, which will reference the user who actually created the service. --- migrations/versions/0284_0283_retry.py | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 migrations/versions/0284_0283_retry.py diff --git a/migrations/versions/0284_0283_retry.py b/migrations/versions/0284_0283_retry.py new file mode 100644 index 000000000..44ba5d841 --- /dev/null +++ b/migrations/versions/0284_0283_retry.py @@ -0,0 +1,39 @@ +"""empty message + +Revision ID: 0284_0283_retry +Revises: 0283_platform_admin_not_live +Create Date: 2016-10-25 17:37:27.660723 + +""" + +# revision identifiers, used by Alembic. +revision = '0284_0283_retry' +down_revision = '0283_platform_admin_not_live' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.execute(""" + UPDATE + services + SET + count_as_live = not users.platform_admin + FROM + users, services_history + WHERE + services_history.id = services.id and + services_history.version = 1 and + services_history.created_by_id = users.id + ; + """) + +def downgrade(): + op.execute(""" + UPDATE + services + SET + count_as_live = true + ; + """)