Skip to content

Commit

Permalink
Only mark migrations applied that were not previously mark applied
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythicaeda committed Jan 24, 2025
1 parent df43408 commit 5968f6e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion deployment/aerie_db_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def mark_current_version(self) -> int:
if migration_ids.pop(0)[0] != 'migration_id':
exit_with_error("Error while fetching current schema information.")


applied_ids = self.get_migrate_status()

# migration_ids now looks like [['0'], ['1'], ... ['n']]
prev_id = -1
cur_id = 0
Expand All @@ -159,7 +162,14 @@ def mark_current_version(self) -> int:
if cur_id != prev_id + 1:
exit_with_error(f'Gap detected in applied migrations. \n\tLast migration: {prev_id} \tNext migration: {cur_id}'
f'\n\tTo resolve, manually revert all migrations following {prev_id}, then run this script again.')
# Ensure migration is marked as applied

# Skip marking a migration as applied if it is already applied
split = applied_ids[cur_id].split()
if split[0] == i[0] and len(split) == 4:
prev_id = cur_id
continue

# If a migration is not marked as applied, mark it as such
self.migrate('apply', f'--skip-execution --version {cur_id}', no_output=True)
prev_id = cur_id

Expand Down

0 comments on commit 5968f6e

Please sign in to comment.