From 84fb908261b75e3b8dc4ad553831762524e5a41b Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Mon, 30 Oct 2017 16:03:28 -0400 Subject: [PATCH 1/6] Fix 3.1 to 3.2 migration paths --- .../0005_squashed_v310_v313_updates.py | 31 ++---------- .../0005a_squashed_v310_v313_updates.py | 28 ----------- .../0005b_squashed_v310_v313_updates.py | 24 --------- awx/main/migrations/0006_v320_release.py | 6 ++- awx/main/migrations/_squashed.py | 50 +++++++++++++++++++ awx/main/migrations/_squashed_310.py | 50 +++++++++++++++++++ 6 files changed, 110 insertions(+), 79 deletions(-) delete mode 100644 awx/main/migrations/0005a_squashed_v310_v313_updates.py delete mode 100644 awx/main/migrations/0005b_squashed_v310_v313_updates.py create mode 100644 awx/main/migrations/_squashed.py create mode 100644 awx/main/migrations/_squashed_310.py diff --git a/awx/main/migrations/0005_squashed_v310_v313_updates.py b/awx/main/migrations/0005_squashed_v310_v313_updates.py index 85dac8bbaa..e49b6b227c 100644 --- a/awx/main/migrations/0005_squashed_v310_v313_updates.py +++ b/awx/main/migrations/0005_squashed_v310_v313_updates.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +from django.db import migrations -from django.db import migrations, models +import _squashed +from _squashed_310 import SQUASHED_310 class Migration(migrations.Migration): @@ -10,28 +12,5 @@ class Migration(migrations.Migration): ('main', '0004_squashed_v310_release'), ] - replaces = [ - (b'main', '0035_v310_remove_tower_settings'), - ] - - operations = [ - # Remove Tower settings, these settings are now in separate awx.conf app. - migrations.RemoveField( - model_name='towersettings', - name='user', - ), - migrations.DeleteModel( - name='TowerSettings', - ), - - migrations.AlterField( - model_name='project', - name='scm_type', - field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'), - ), - migrations.AlterField( - model_name='projectupdate', - name='scm_type', - field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'), - ), - ] + replaces = _squashed.replaces(SQUASHED_310) + operations = _squashed.operations(SQUASHED_310) diff --git a/awx/main/migrations/0005a_squashed_v310_v313_updates.py b/awx/main/migrations/0005a_squashed_v310_v313_updates.py deleted file mode 100644 index 6599268ce1..0000000000 --- a/awx/main/migrations/0005a_squashed_v310_v313_updates.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('main', '0005_squashed_v310_v313_updates'), - ] - - replaces = [ - (b'main', '0036_v311_insights'), - ] - - operations = [ - migrations.AlterField( - model_name='project', - name='scm_type', - field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'), - ), - migrations.AlterField( - model_name='projectupdate', - name='scm_type', - field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'), - ), - ] \ No newline at end of file diff --git a/awx/main/migrations/0005b_squashed_v310_v313_updates.py b/awx/main/migrations/0005b_squashed_v310_v313_updates.py deleted file mode 100644 index ea9d26d2bc..0000000000 --- a/awx/main/migrations/0005b_squashed_v310_v313_updates.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('main', '0005a_squashed_v310_v313_updates'), - ] - - replaces = [ - (b'main', '0037_v313_instance_version'), - ] - - operations = [ - # Remove Tower settings, these settings are now in separate awx.conf app. - migrations.AddField( - model_name='instance', - name='version', - field=models.CharField(max_length=24, blank=True), - ), - ] diff --git a/awx/main/migrations/0006_v320_release.py b/awx/main/migrations/0006_v320_release.py index 4cb87f4fba..af0bd9def0 100644 --- a/awx/main/migrations/0006_v320_release.py +++ b/awx/main/migrations/0006_v320_release.py @@ -18,7 +18,11 @@ from awx.main.models import Host class Migration(migrations.Migration): dependencies = [ - ('main', '0005b_squashed_v310_v313_updates'), + ('main', '0005_squashed_v310_v313_updates'), + ] + + replaces = [ + ('main', '0005a_squashed_v310_v313_updates'), ] operations = [ diff --git a/awx/main/migrations/_squashed.py b/awx/main/migrations/_squashed.py new file mode 100644 index 0000000000..8344f8b6ed --- /dev/null +++ b/awx/main/migrations/_squashed.py @@ -0,0 +1,50 @@ +from itertools import chain +from django.db import ( + connection, + migrations, +) + + +def squash_data(SQUASHED): + '''Returns a tuple of the squashed_keys and the key position to begin + processing replace and operation lists''' + + cm = current_migration() + squashed_keys = sorted(SQUASHED.keys()) + try: + if cm is None: + key_index = 0 + else: + key_index = squashed_keys.index(cm.name) + 1 + except ValueError: + key_index = 0 + return squashed_keys, key_index + + +def current_migration(): + '''Get the latest migration non-squashed migration''' + try: + recorder = migrations.recorder.MigrationRecorder(connection) + return recorder.migration_qs.filter(app='main').exclude(name__contains='squashed').latest('id') + except recorder.Migration.DoesNotExist: + return None + + +def replaces(SQUASHED): + '''Build a list of replacement migrations based on the most recent non-squashed migration + and the provided list of SQUASHED migrations. If the most recent non-squashed migration + is not present anywhere in the SQUASHED dictionary, assume they have all been applied. + ''' + squashed_keys, key_index = squash_data(SQUASHED) + return [(b'main', key) for key in squashed_keys[key_index:]] + + +def operations(SQUASHED): + '''Build a list of migration operations based on the most recent non-squashed migration + and the provided list of SQUASHED migrations. If the most recent non-squashed migration + is not present anywhere in the SQUASHED dictionary, assume they have all been applied. + ''' + squashed_keys, key_index = squash_data(SQUASHED) + op_keys = squashed_keys[key_index:] + ops = [SQUASHED[op_key] for op_key in op_keys] + return [op for op in chain.from_iterable(ops)] diff --git a/awx/main/migrations/_squashed_310.py b/awx/main/migrations/_squashed_310.py new file mode 100644 index 0000000000..0813c19c3e --- /dev/null +++ b/awx/main/migrations/_squashed_310.py @@ -0,0 +1,50 @@ +from django.db import ( + migrations, + models, +) + +SQUASHED_310 = { + '0035_v310_remove_tower_settings': [ + # Remove Tower settings, these settings are now in separate awx.conf app. + migrations.RemoveField( + model_name='towersettings', + name='user', + ), + migrations.DeleteModel( + name='TowerSettings', + ), + + migrations.AlterField( + model_name='project', + name='scm_type', + field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'), + ), + migrations.AlterField( + model_name='projectupdate', + name='scm_type', + field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'), + ), + ], + '0036_v311_insights': [ + migrations.AlterField( + model_name='project', + name='scm_type', + field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'), + ), + migrations.AlterField( + model_name='projectupdate', + name='scm_type', + field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'), + ), + ], + '0037_v313_instance_version': [ + # Remove Tower settings, these settings are now in separate awx.conf app. + migrations.AddField( + model_name='instance', + name='version', + field=models.CharField(max_length=24, blank=True), + ), + ], +} + +__all__ = ['SQUASHED_310'] From fc56a1c1706601332714a6dbebb3ed087de57829 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Tue, 31 Oct 2017 00:46:33 -0400 Subject: [PATCH 2/6] Fix 3.0 to 3.2 migration paths --- .../0003_squashed_v300_v303_updates.py | 41 ++----------- awx/main/migrations/_squashed.py | 29 ++++----- awx/main/migrations/_squashed_300.py | 60 +++++++++++++++++++ 3 files changed, 79 insertions(+), 51 deletions(-) create mode 100644 awx/main/migrations/_squashed_300.py diff --git a/awx/main/migrations/0003_squashed_v300_v303_updates.py b/awx/main/migrations/0003_squashed_v300_v303_updates.py index 82d781ec85..661debec98 100644 --- a/awx/main/migrations/0003_squashed_v300_v303_updates.py +++ b/awx/main/migrations/0003_squashed_v300_v303_updates.py @@ -8,14 +8,9 @@ from __future__ import unicode_literals from django.db import migrations, models from django.conf import settings import awx.main.fields -import jsonfield.fields - -def update_dashed_host_variables(apps, schema_editor): - Host = apps.get_model('main', 'Host') - for host in Host.objects.filter(variables='---'): - host.variables = '' - host.save() +import _squashed +from _squashed_300 import SQUASHED_300 class Migration(migrations.Migration): @@ -27,12 +22,7 @@ class Migration(migrations.Migration): (b'main', '0025_v300_update_rbac_parents'), (b'main', '0026_v300_credential_unique'), (b'main', '0027_v300_team_migrations'), - (b'main', '0028_v300_org_team_cascade'), - (b'main', '0029_v302_add_ask_skip_tags'), - (b'main', '0030_v302_job_survey_passwords'), - (b'main', '0031_v302_migrate_survey_passwords'), - (b'main', '0032_v302_credential_permissions_update'), - (b'main', '0033_v303_v245_host_variable_fix'),] + (b'main', '0028_v300_org_team_cascade')] + _squashed.replaces(SQUASHED_300) dependencies = [ @@ -130,27 +120,4 @@ class Migration(migrations.Migration): field=models.ForeignKey(related_name='teams', to='main.Organization'), preserve_default=False, ), - # add ask skip tags - migrations.AddField( - model_name='jobtemplate', - name='ask_skip_tags_on_launch', - field=models.BooleanField(default=False), - ), - # job survery passwords - migrations.AddField( - model_name='job', - name='survey_passwords', - field=jsonfield.fields.JSONField(default={}, editable=False, blank=True), - ), - # RBAC credential permission updates - migrations.AlterField( - model_name='credential', - name='admin_role', - field=awx.main.fields.ImplicitRoleField(related_name='+', parent_role=[b'singleton:system_administrator', b'organization.admin_role'], to='main.Role', null=b'True'), - ), - migrations.AlterField( - model_name='credential', - name='use_role', - field=awx.main.fields.ImplicitRoleField(related_name='+', parent_role=[b'admin_role'], to='main.Role', null=b'True'), - ), - ] + ] + _squashed.operations(SQUASHED_300) diff --git a/awx/main/migrations/_squashed.py b/awx/main/migrations/_squashed.py index 8344f8b6ed..709a0a8869 100644 --- a/awx/main/migrations/_squashed.py +++ b/awx/main/migrations/_squashed.py @@ -2,20 +2,21 @@ from itertools import chain from django.db import ( connection, migrations, + OperationalError, ) -def squash_data(SQUASHED): +def squash_data(squashed): '''Returns a tuple of the squashed_keys and the key position to begin processing replace and operation lists''' cm = current_migration() - squashed_keys = sorted(SQUASHED.keys()) + squashed_keys = sorted(squashed.keys()) + if cm is None: + return squashed_keys, 0 + try: - if cm is None: - key_index = 0 - else: - key_index = squashed_keys.index(cm.name) + 1 + key_index = squashed_keys.index(cm.name) + 1 except ValueError: key_index = 0 return squashed_keys, key_index @@ -26,25 +27,25 @@ def current_migration(): try: recorder = migrations.recorder.MigrationRecorder(connection) return recorder.migration_qs.filter(app='main').exclude(name__contains='squashed').latest('id') - except recorder.Migration.DoesNotExist: + except (recorder.Migration.DoesNotExist, OperationalError): return None -def replaces(SQUASHED): +def replaces(squashed): '''Build a list of replacement migrations based on the most recent non-squashed migration and the provided list of SQUASHED migrations. If the most recent non-squashed migration is not present anywhere in the SQUASHED dictionary, assume they have all been applied. ''' - squashed_keys, key_index = squash_data(SQUASHED) + squashed_keys, key_index = squash_data(squashed) return [(b'main', key) for key in squashed_keys[key_index:]] -def operations(SQUASHED): +def operations(squashed): '''Build a list of migration operations based on the most recent non-squashed migration - and the provided list of SQUASHED migrations. If the most recent non-squashed migration - is not present anywhere in the SQUASHED dictionary, assume they have all been applied. + and the provided list of squashed migrations. If the most recent non-squashed migration + is not present anywhere in the `squashed` dictionary, assume they have all been applied. ''' - squashed_keys, key_index = squash_data(SQUASHED) + squashed_keys, key_index = squash_data(squashed) op_keys = squashed_keys[key_index:] - ops = [SQUASHED[op_key] for op_key in op_keys] + ops = [squashed[op_key] for op_key in op_keys] return [op for op in chain.from_iterable(ops)] diff --git a/awx/main/migrations/_squashed_300.py b/awx/main/migrations/_squashed_300.py new file mode 100644 index 0000000000..904c036db1 --- /dev/null +++ b/awx/main/migrations/_squashed_300.py @@ -0,0 +1,60 @@ +from django.db import ( + migrations, + models, +) +import jsonfield.fields +import awx.main.fields + +from awx.main.migrations import _save_password_keys +from awx.main.migrations import _migration_utils as migration_utils + + +def update_dashed_host_variables(apps, schema_editor): + Host = apps.get_model('main', 'Host') + for host in Host.objects.filter(variables='---'): + host.variables = '' + host.save() + + +SQUASHED_300 = { + '0029_v302_add_ask_skip_tags': [ + # add ask skip tags + migrations.AddField( + model_name='jobtemplate', + name='ask_skip_tags_on_launch', + field=models.BooleanField(default=False), + ), + ], + '0030_v302_job_survey_passwords': [ + # job survery passwords + migrations.AddField( + model_name='job', + name='survey_passwords', + field=jsonfield.fields.JSONField(default={}, editable=False, blank=True), + ), + ], + '0031_v302_migrate_survey_passwords': [ + migrations.RunPython(migration_utils.set_current_apps_for_migrations), + migrations.RunPython(_save_password_keys.migrate_survey_passwords), + ], + '0032_v302_credential_permissions_update': [ + # RBAC credential permission updates + migrations.AlterField( + model_name='credential', + name='admin_role', + field=awx.main.fields.ImplicitRoleField(related_name='+', parent_role=[b'singleton:system_administrator', b'organization.admin_role'], to='main.Role', null=b'True'), + ), + migrations.AlterField( + model_name='credential', + name='use_role', + field=awx.main.fields.ImplicitRoleField(related_name='+', parent_role=[b'admin_role'], to='main.Role', null=b'True'), + ), + ], + '0033_v303_v245_host_variable_fix': [ + migrations.RunPython(migration_utils.set_current_apps_for_migrations), + migrations.RunPython(update_dashed_host_variables), + ], +} + + +__all__ = ['SQUASHED_300'] From af3e6f792c3faf1bd70bde01865e01f49b7b9c0a Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Tue, 31 Oct 2017 11:18:31 -0400 Subject: [PATCH 3/6] Rename squash 310 to 31 --- awx/main/migrations/0005_squashed_v310_v313_updates.py | 6 +++--- awx/main/migrations/{_squashed_310.py => _squashed_31.py} | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename awx/main/migrations/{_squashed_310.py => _squashed_31.py} (98%) diff --git a/awx/main/migrations/0005_squashed_v310_v313_updates.py b/awx/main/migrations/0005_squashed_v310_v313_updates.py index e49b6b227c..3a2e05e270 100644 --- a/awx/main/migrations/0005_squashed_v310_v313_updates.py +++ b/awx/main/migrations/0005_squashed_v310_v313_updates.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals from django.db import migrations import _squashed -from _squashed_310 import SQUASHED_310 +from _squashed_31 import SQUASHED_31 class Migration(migrations.Migration): @@ -12,5 +12,5 @@ class Migration(migrations.Migration): ('main', '0004_squashed_v310_release'), ] - replaces = _squashed.replaces(SQUASHED_310) - operations = _squashed.operations(SQUASHED_310) + replaces = _squashed.replaces(SQUASHED_31) + operations = _squashed.operations(SQUASHED_31) diff --git a/awx/main/migrations/_squashed_310.py b/awx/main/migrations/_squashed_31.py similarity index 98% rename from awx/main/migrations/_squashed_310.py rename to awx/main/migrations/_squashed_31.py index 0813c19c3e..3c43c26a48 100644 --- a/awx/main/migrations/_squashed_310.py +++ b/awx/main/migrations/_squashed_31.py @@ -3,7 +3,7 @@ from django.db import ( models, ) -SQUASHED_310 = { +SQUASHED_31 = { '0035_v310_remove_tower_settings': [ # Remove Tower settings, these settings are now in separate awx.conf app. migrations.RemoveField( @@ -47,4 +47,4 @@ SQUASHED_310 = { ], } -__all__ = ['SQUASHED_310'] +__all__ = ['SQUASHED_31'] From 47a3ba9bd51c1c0a2e5291b37066534ed8850ba2 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Tue, 31 Oct 2017 11:19:50 -0400 Subject: [PATCH 4/6] Rename squash 300 to 30 --- awx/main/migrations/0003_squashed_v300_v303_updates.py | 6 +++--- awx/main/migrations/{_squashed_300.py => _squashed_30.py} | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename awx/main/migrations/{_squashed_300.py => _squashed_30.py} (97%) diff --git a/awx/main/migrations/0003_squashed_v300_v303_updates.py b/awx/main/migrations/0003_squashed_v300_v303_updates.py index 661debec98..39635353c1 100644 --- a/awx/main/migrations/0003_squashed_v300_v303_updates.py +++ b/awx/main/migrations/0003_squashed_v300_v303_updates.py @@ -10,7 +10,7 @@ from django.conf import settings import awx.main.fields import _squashed -from _squashed_300 import SQUASHED_300 +from _squashed_30 import SQUASHED_30 class Migration(migrations.Migration): @@ -22,7 +22,7 @@ class Migration(migrations.Migration): (b'main', '0025_v300_update_rbac_parents'), (b'main', '0026_v300_credential_unique'), (b'main', '0027_v300_team_migrations'), - (b'main', '0028_v300_org_team_cascade')] + _squashed.replaces(SQUASHED_300) + (b'main', '0028_v300_org_team_cascade')] + _squashed.replaces(SQUASHED_30) dependencies = [ @@ -120,4 +120,4 @@ class Migration(migrations.Migration): field=models.ForeignKey(related_name='teams', to='main.Organization'), preserve_default=False, ), - ] + _squashed.operations(SQUASHED_300) + ] + _squashed.operations(SQUASHED_30) diff --git a/awx/main/migrations/_squashed_300.py b/awx/main/migrations/_squashed_30.py similarity index 97% rename from awx/main/migrations/_squashed_300.py rename to awx/main/migrations/_squashed_30.py index 904c036db1..5dd99762d6 100644 --- a/awx/main/migrations/_squashed_300.py +++ b/awx/main/migrations/_squashed_30.py @@ -16,7 +16,7 @@ def update_dashed_host_variables(apps, schema_editor): host.save() -SQUASHED_300 = { +SQUASHED_30 = { '0029_v302_add_ask_skip_tags': [ # add ask skip tags migrations.AddField( @@ -57,4 +57,4 @@ SQUASHED_300 = { } -__all__ = ['SQUASHED_300'] +__all__ = ['SQUASHED_30'] From f9685717b826b4fe0888134a92c7534607fb7ad5 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Thu, 2 Nov 2017 11:41:59 -0400 Subject: [PATCH 5/6] Move post 3.0 migrations to pre 3.1 position in migration files --- awx/main/migrations/0003_squashed_v300_v303_updates.py | 8 ++------ awx/main/migrations/0004_squashed_v310_release.py | 7 +++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/awx/main/migrations/0003_squashed_v300_v303_updates.py b/awx/main/migrations/0003_squashed_v300_v303_updates.py index 39635353c1..042c036665 100644 --- a/awx/main/migrations/0003_squashed_v300_v303_updates.py +++ b/awx/main/migrations/0003_squashed_v300_v303_updates.py @@ -9,9 +9,6 @@ from django.db import migrations, models from django.conf import settings import awx.main.fields -import _squashed -from _squashed_30 import SQUASHED_30 - class Migration(migrations.Migration): replaces = [(b'main', '0020_v300_labels_changes'), @@ -22,8 +19,7 @@ class Migration(migrations.Migration): (b'main', '0025_v300_update_rbac_parents'), (b'main', '0026_v300_credential_unique'), (b'main', '0027_v300_team_migrations'), - (b'main', '0028_v300_org_team_cascade')] + _squashed.replaces(SQUASHED_30) - + (b'main', '0028_v300_org_team_cascade')] dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), @@ -120,4 +116,4 @@ class Migration(migrations.Migration): field=models.ForeignKey(related_name='teams', to='main.Organization'), preserve_default=False, ), - ] + _squashed.operations(SQUASHED_30) + ] diff --git a/awx/main/migrations/0004_squashed_v310_release.py b/awx/main/migrations/0004_squashed_v310_release.py index e4b1df2290..f4263feaa3 100644 --- a/awx/main/migrations/0004_squashed_v310_release.py +++ b/awx/main/migrations/0004_squashed_v310_release.py @@ -8,6 +8,9 @@ import django.db.models.deletion import awx.main.models.workflow import awx.main.fields +import _squashed +from _squashed_30 import SQUASHED_30 + class Migration(migrations.Migration): @@ -15,11 +18,11 @@ class Migration(migrations.Migration): ('main', '0003_squashed_v300_v303_updates'), ] - replaces = [ + replaces = _squashed.replaces(SQUASHED_30) + [ (b'main', '0034_v310_release'), ] - operations = [ + operations = _squashed.operations(SQUASHED_30) + [ # Create ChannelGroup table migrations.CreateModel( name='ChannelGroup', From 2f86774006b345e79e659eeee9724e539d4794f7 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Thu, 2 Nov 2017 15:40:30 -0400 Subject: [PATCH 6/6] 3.2.0 should not have any replacements defined unless 0005a or 0005b migrations have been run previously --- awx/main/migrations/0006_v320_release.py | 21 +++++++++++++++++---- awx/main/migrations/_squashed.py | 7 +++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/awx/main/migrations/0006_v320_release.py b/awx/main/migrations/0006_v320_release.py index af0bd9def0..173e649c77 100644 --- a/awx/main/migrations/0006_v320_release.py +++ b/awx/main/migrations/0006_v320_release.py @@ -6,7 +6,12 @@ from __future__ import unicode_literals from psycopg2.extensions import AsIs # Django -from django.db import migrations, models +from django.db import ( + connection, + migrations, + models, + OperationalError +) from django.conf import settings import taggit.managers @@ -15,15 +20,23 @@ import awx.main.fields from awx.main.models import Host +def replaces(): + squashed = ['0005a_squashed_v310_v313_updates', '0005b_squashed_v310_v313_updates'] + try: + recorder = migrations.recorder.MigrationRecorder(connection) + result = recorder.migration_qs.filter(app='main').filter(name__in=squashed).all() + return [('main', m.name) for m in result] + except OperationalError: + return [] + + class Migration(migrations.Migration): dependencies = [ ('main', '0005_squashed_v310_v313_updates'), ] - replaces = [ - ('main', '0005a_squashed_v310_v313_updates'), - ] + replaces = replaces() operations = [ # Release UJT unique_together constraint diff --git a/awx/main/migrations/_squashed.py b/awx/main/migrations/_squashed.py index 709a0a8869..c7de8c9cd0 100644 --- a/awx/main/migrations/_squashed.py +++ b/awx/main/migrations/_squashed.py @@ -22,11 +22,14 @@ def squash_data(squashed): return squashed_keys, key_index -def current_migration(): +def current_migration(exclude_squashed=True): '''Get the latest migration non-squashed migration''' try: recorder = migrations.recorder.MigrationRecorder(connection) - return recorder.migration_qs.filter(app='main').exclude(name__contains='squashed').latest('id') + migration_qs = recorder.migration_qs.filter(app='main') + if exclude_squashed: + migration_qs = migration_qs.exclude(name__contains='squashed') + return migration_qs.latest('id') except (recorder.Migration.DoesNotExist, OperationalError): return None