Skip to content

Commit

Permalink
running db migrations on deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
srh-sloan committed Sep 18, 2024
1 parent 3c6dae0 commit 5419f06
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/copilot_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
environment: dev
app_name: fund-application-builder
version: sha-${{ github.sha }}
db_name: fs-fund-builder

post_dev_deploy_tests:
needs: dev_deploy
Expand Down Expand Up @@ -103,6 +104,7 @@ jobs:
environment: test
app_name: fund-application-builder
version: sha-${{ github.sha }}
db_name: fs-fund-builder

post_test_deploy_tests:
needs: test_deploy
Expand Down Expand Up @@ -131,6 +133,7 @@ jobs:
environment: uat
app_name: fund-application-builder
version: sha-${{ github.sha }}
db_name: fs-fund-builder

post_uat_deploy_tests:
needs: uat_deploy
Expand Down Expand Up @@ -159,3 +162,4 @@ jobs:
environment: prod
app_name: fund-application-builder
version: sha-${{ github.sha }}
db_name: fs-fund-builder
38 changes: 38 additions & 0 deletions scripts/migration-task-script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
import re
import subprocess
import sys

command_to_run = "flask db upgrade"
environment = sys.argv[1]
service = sys.argv[2]

try:
command = subprocess.run(
args=[
"copilot",
"task",
"run",
"--generate-cmd",
f"pre-award/{environment}/{service}",
],
capture_output=True,
check=True,
text=True,
)
# Strip image argument as we want to build a new image to pick up new migrations
command_with_image_removed = re.sub(r"--image \S+", "", command.stderr)
except subprocess.CalledProcessError as e:
print(e.stderr)
raise e

# Remove final line break and append arguments
try:
subprocess.run(
args=command_with_image_removed[:-1] + f" \\\n--follow \\\n--command '{command_to_run}'",
shell=True,
check=True,
)
except subprocess.CalledProcessError as e:
# Don't want to leak the command output here so just exit with the command's return code
sys.exit(e.returncode)

0 comments on commit 5419f06

Please sign in to comment.