Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine migration script #1617

Merged
merged 15 commits into from
Jan 28, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Only mark migrations applied that were not previously mark applied
Mythicaeda committed Jan 28, 2025
commit d887d9c90335048fea08fe8ff28e22a1881e02e7
12 changes: 11 additions & 1 deletion deployment/aerie_db_migration.py
Original file line number Diff line number Diff line change
@@ -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.")

# Get the current migration status from Hasura's perspective for comparison
migrate_status = self.get_migrate_status()

# migration_ids now looks like [['0'], ['1'], ... ['n']]
prev_id = -1
cur_id = 0
@@ -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 = migrate_status[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