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']