From d887d9c90335048fea08fe8ff28e22a1881e02e7 Mon Sep 17 00:00:00 2001 From: Theresa Kamerman Date: Thu, 23 Jan 2025 16:39:16 -0800 Subject: [PATCH] Only mark migrations applied that were not previously mark applied --- deployment/aerie_db_migration.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/deployment/aerie_db_migration.py b/deployment/aerie_db_migration.py index 490fd77566..d513483125 100755 --- a/deployment/aerie_db_migration.py +++ b/deployment/aerie_db_migration.py @@ -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