Skip to content

Commit

Permalink
Fix Migrations Pipeline
Browse files Browse the repository at this point in the history
Fixed the PGCMP Workflow. Checking out `develop` requires re-cloning the `PGCMP` repo

Fixed a bug in the migration script that was causing hasura to reapply migration 1 when bulk migrating down from version 1.

Fixed a typo in the migration script preventing the "mark correct version" command from applying
  • Loading branch information
Mythicaeda committed Apr 24, 2024
1 parent 1abfe04 commit 926f50d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/pgcmp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ jobs:
env:
AERIE_USERNAME: "${{secrets.AERIE_USERNAME}}"
AERIE_PASSWORD: "${{secrets.AERIE_PASSWORD}}"
- name: Dump Databases
- name: Clone PGCMP
uses: actions/checkout@v4
with:
repository: cbbrowne/pgcmp
path: pgcmp
- name: Dump Migrated Database
env:
AERIE_USERNAME: "${{secrets.AERIE_USERNAME}}"
AERIE_PASSWORD: "${{secrets.AERIE_PASSWORD}}"
Expand Down Expand Up @@ -193,7 +198,7 @@ jobs:
with:
repository: cbbrowne/pgcmp
path: pgcmp
- name: Dump Databases
- name: Dump Current Database
env:
AERIE_USERNAME: "${{secrets.AERIE_USERNAME}}"
AERIE_PASSWORD: "${{secrets.AERIE_PASSWORD}}"
Expand Down Expand Up @@ -224,7 +229,7 @@ jobs:
env:
AERIE_USERNAME: "${{secrets.AERIE_USERNAME}}"
AERIE_PASSWORD: "${{secrets.AERIE_PASSWORD}}"
- name: Dump Databases
- name: Dump Migrated Database
env:
AERIE_USERNAME: "${{secrets.AERIE_USERNAME}}"
AERIE_PASSWORD: "${{secrets.AERIE_PASSWORD}}"
Expand Down
23 changes: 15 additions & 8 deletions deployment/aerie_db_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def step_by_step_migration(db_migration, apply):
return
input("Press Enter to continue...")

def bulk_migration(db_migration, apply):
def bulk_migration(db_migration, apply, current_version):
# Migrate the database
exit_with = 0
if apply:
Expand All @@ -98,10 +98,15 @@ def bulk_migration(db_migration, apply):
if exit_code != 0:
exit_with = 1
else:
os.system(f'hasura migrate apply --goto 1 --database-name {db_migration.db_name} --dry-run --log-level WARN &&'
f'hasura migrate apply --down 1 --database-name {db_migration.db_name} --dry-run --log-level WARN')
exit_code = os.system(f'hasura migrate apply --goto 1 --database-name {db_migration.db_name} &&'
f'hasura migrate apply --down 1 --database-name {db_migration.db_name}')
# Performing GOTO 1 when the database is at migration 1 will cause Hasura to attempt to reapply migration 1
if current_version == 1:
os.system(f'hasura migrate apply --down 1 --database-name {db_migration.db_name} --dry-run --log-level WARN')
exit_code = os.system(f'hasura migrate apply --down 1 --database-name {db_migration.db_name}')
else:
os.system(f'hasura migrate apply --goto 1 --database-name {db_migration.db_name} --dry-run --log-level WARN &&'
f'hasura migrate apply --down 1 --database-name {db_migration.db_name} --dry-run --log-level WARN')
exit_code = os.system(f'hasura migrate apply --goto 1 --database-name {db_migration.db_name} &&'
f'hasura migrate apply --down 1 --database-name {db_migration.db_name}')
if exit_code != 0:
exit_with = 1

Expand All @@ -128,7 +133,9 @@ def mark_current_version(username, password, netloc):

# Mark everything up to that as applied
for i in range(0, current_schema+1):
os.system('hasura migrate apply --skip-execution --version '+str(i)+' --database-name aerie >/dev/null 2>&1')
os.system('hasura migrate apply --skip-execution --version '+str(i)+' --database-name Aerie >/dev/null 2>&1')

return current_schema

def main():
# Create a cli parser
Expand Down Expand Up @@ -227,7 +234,7 @@ def main():
os.chdir(HASURA_PATH)

# Mark all migrations previously applied to the databases to be updated as such
mark_current_version(username, password, args.network_location)
current_version = mark_current_version(username, password, args.network_location)

clear_screen()
print(f'\n###############################'
Expand All @@ -238,7 +245,7 @@ def main():
# Go step-by-step through the migrations available for the selected database
step_by_step_migration(migration, args.apply)
else:
bulk_migration(migration, args.apply)
bulk_migration(migration, args.apply, current_version)

if __name__ == "__main__":
main()

0 comments on commit 926f50d

Please sign in to comment.