From f7349b4781a9f197f22fba276b4dec3192c5082d Mon Sep 17 00:00:00 2001 From: Edward Date: Mon, 20 May 2019 14:43:13 -0300 Subject: [PATCH] =?UTF-8?q?Conserta=20erro=20de=20migra=C3=A7=C3=A3o=20Blo?= =?UTF-8?q?co=20(#2792)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0029_auto_20190517_1531.py | 65 ++++++++++++++----- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/sapl/parlamentares/migrations/0029_auto_20190517_1531.py b/sapl/parlamentares/migrations/0029_auto_20190517_1531.py index ef24afd91..30a5c64ec 100644 --- a/sapl/parlamentares/migrations/0029_auto_20190517_1531.py +++ b/sapl/parlamentares/migrations/0029_auto_20190517_1531.py @@ -13,22 +13,55 @@ class Migration(migrations.Migration): operations = [ migrations.RunSQL(""" - update base_autor - set tipo_id = (select id - from base_tipoautor - where content_type_id = (select id - from django_content_type - where app_label = 'parlamentares' and model = 'bloco')) - where tipo_id = (select id - from base_tipoautor - where content_type_id = (select id - from django_content_type - where app_label = 'sessao' and model = 'bloco')); + INSERT INTO django_content_type (app_label, model) + SELECT 'parlamentares', 'bloco' + WHERE NOT EXISTS (SELECT id + FROM django_content_type + WHERE app_label = 'parlamentares' AND model = 'bloco'); """), migrations.RunSQL(""" - delete from base_tipoautor - where content_type_id = (select id - from django_content_type - where app_label = 'sessao' and model = 'bloco') - """) + INSERT INTO base_tipoautor (descricao, content_type_id) + SELECT 'Bloco Parlamentar', (SELECT id + FROM django_content_type + WHERE app_label = 'parlamentares' AND model = 'bloco') + WHERE NOT EXISTS (SELECT id + FROM base_tipoautor + WHERE content_type_id = (SELECT id + FROM django_content_type + WHERE app_label = 'parlamentares' AND model = 'bloco')); + """), + migrations.RunSQL(""" + UPDATE auth_permission + SET content_type_id = (SELECT id + FROM django_content_type + WHERE app_label = 'parlamentares' AND model = 'bloco') + WHERE content_type_id = (SELECT id + FROM django_content_type + WHERE app_label = 'sessao' AND model = 'bloco') + AND NOT EXISTS (SELECT id + FROM django_content_type + WHERE app_label = 'parlamentares' AND model = 'bloco'); + """), + migrations.RunSQL(""" + UPDATE base_autor + SET tipo_id = (SELECT id + FROM base_tipoautor + WHERE content_type_id = (SELECT id + FROM django_content_type + WHERE app_label = 'parlamentares' AND model = 'bloco')), + content_type_id = (SELECT id + FROM django_content_type + WHERE app_label = 'parlamentares' AND model = 'bloco') + WHERE tipo_id = (SELECT id + FROM base_tipoautor + WHERE content_type_id = (SELECT id + FROM django_content_type + WHERE app_label = 'sessao' AND model = 'bloco')); + """), + migrations.RunSQL(""" + DELETE FROM base_tipoautor + WHERE content_type_id = (SELECT id + FROM django_content_type + WHERE app_label = 'sessao' AND model = 'bloco'); + """), ]