From 249a5e5e4d4028250579b9206ed79d811a430c32 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Fri, 17 Nov 2017 11:32:17 -0500 Subject: [PATCH] Include all previously run operations to satisfy Django migration planner. --- .../migrations/0003_squashed_v300_v303_updates.py | 7 +++++-- awx/main/migrations/_squashed.py | 14 +++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/awx/main/migrations/0003_squashed_v300_v303_updates.py b/awx/main/migrations/0003_squashed_v300_v303_updates.py index 042c036665..48210bfa48 100644 --- a/awx/main/migrations/0003_squashed_v300_v303_updates.py +++ b/awx/main/migrations/0003_squashed_v300_v303_updates.py @@ -9,6 +9,9 @@ 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'), @@ -19,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')] + (b'main', '0028_v300_org_team_cascade')] + _squashed.replaces(SQUASHED_30, applied=True) dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), @@ -116,4 +119,4 @@ class Migration(migrations.Migration): field=models.ForeignKey(related_name='teams', to='main.Organization'), preserve_default=False, ), - ] + ] + _squashed.operations(SQUASHED_30, applied=True) diff --git a/awx/main/migrations/_squashed.py b/awx/main/migrations/_squashed.py index 1470df54ce..e2f19970b4 100644 --- a/awx/main/migrations/_squashed.py +++ b/awx/main/migrations/_squashed.py @@ -35,21 +35,29 @@ def current_migration(exclude_squashed=True): return None -def replaces(squashed): +def replaces(squashed, applied=False): '''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. + + If applied is True, this will return a list of all the migrations that have already + been applied. ''' squashed_keys, key_index = squash_data(squashed) + if applied: + return [(b'main', key) for key in squashed_keys[:key_index]] return [(b'main', key) for key in squashed_keys[key_index:]] -def operations(squashed): +def operations(squashed, applied=False): '''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. + + If applied is True, this will return a list of all the operations that have + already been applied. ''' squashed_keys, key_index = squash_data(squashed) - op_keys = squashed_keys[key_index:] + op_keys = squashed_keys[:key_index] if applied else squashed_keys[key_index:] ops = [squashed[op_key] for op_key in op_keys] return [op for op in chain.from_iterable(ops)]