Database Migrations #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Database Migrations | |
on: | |
workflow_dispatch: | |
permissions: | |
id-token: write | |
contents: read | |
env: | |
AWS_REGION: ap-south-1 | |
ECR_REGISTRY: 685797548389.dkr.ecr.ap-south-1.amazonaws.com | |
ECR_REPOSITORY: dtmweb | |
jobs: | |
migration: | |
name: Do migration on RDS | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ github.ref_name }} | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.ref }} | |
- name: Setup AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
audience: sts.amazonaws.com | |
aws-region: ${{ env.AWS_REGION }} | |
role-session-name: GH-Actions-${{ github.run_id }}-${{ github.run_attempt }} | |
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }} | |
- name: Run migration command | |
id: run-migration | |
shell: bash | |
run: | | |
TASK_ID=`aws ecs list-tasks --cluster ${{ secrets.ECS_CLUSTER_NAME }} --service ${{ secrets.ECS_SERVICE_NAME }} | jq -r .taskArns[0]` | |
aws ecs execute-command --cluster dtm-ecs-cluster --task $TASK_ID --region ${{env.AWS_REGION}} --interactive --command "/bin/bash -c 'pdm run alembic upgrade head'" |