Skip to content

Commit

Permalink
BCDA-8760: Add migrate db workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpartridge committed Feb 21, 2025
1 parent 02de50c commit cb70180
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/migrate-db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Migrate DB

on:
workflow_call:
inputs:
release_version:
description: 'Release version (or branch name)'
required: true
type: string
env:
description: 'Environment you want to migrate for (dev, test, sbx, prod)'
required: true
type: string
workflow_dispatch:
inputs:
release_version:
description: 'Release version (or branch name)'
required: true
type: string
env:
description: 'Environment you want to migrate for (dev, test, sbx, prod)'
required: true
default: dev
type: choice
options:
- dev
- test
- sbx
- prod

permissions:
id-token: write
contents: read

jobs:
migrate_db:
name: Migrate DB
runs-on: self-hosted
steps:
- name: Checkout SSAS
uses: actions/checkout@v4
with:
repository: CMSgov/bcda-ssas-app
ref: ${{ inputs.release_version }}
- name: Get AWS params
uses: cmsgov/ab2d-bcda-dpc-platform/actions/aws-params-env-action@main
env:
AWS_REGION: ${{ vars.AWS_REGION }}
with:
params: |
DB_URL=/bcda/${{ inputs.env }}/api/DATABASE_URL
- name: Get Go
uses: actions/setup-go@v5
with:
go-version: '>=1.23.6'
- name: Get golang-migrate
run: go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
- name: Set DB name
if: ${{ inputs.env == 'dev' }}
run: echo "DB_NAME=bcda-dev-rds" >> "$GITHUB_OUTPUT"
- name: Set DB name
if: ${{ inputs.env == 'test' }}
run: echo "DB_NAME=bcda-test-rds" >> "$GITHUB_OUTPUT"
- name: Set DB name
if: ${{ inputs.env == 'sbx' }}
run: echo "DB_NAME=bcda-opensbx-rds-20190311" >> "$GITHUB_OUTPUT"
- name: Set DB name
if: ${{ inputs.env == 'prod' }}
run: echo "DB_NAME=bcda-prod-rds-20190201" >> "$GITHUB_OUTPUT"
- uses: aws-actions/configure-aws-credentials@v3
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ secrets.ACCOUNT_ID }}:role/delegatedadmin/developer/bcda-${{ inputs.env }}-github-actions
- name: Migrate DB
env:
PGSSLMODE: require
# CAUTION: if changing the script below, validate that sensitive information is not printed in the workflow
run: |
HOST=$(aws rds describe-db-instances --db-instance-identifier ${{ env.DB_NAME }} 2>&1 | jq -r '.DBInstances[0].Endpoint.Address' 2>&1)
CONNECTION_URL=$(echo $DB_URL 2>&1 | sed -E "s/@.*\/bcda/\@$HOST\/bcda/" 2>&1)
migrate -database ${CONNECTION_URL} -path db/migrations/bcda up
- name: Success Alert
if: ${{ success() }}
uses: slackapi/slack-github-action@v2.0.0
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
# Sends to bcda-deploy
payload: |
channel: "C03S23MJFJS"
attachments:
- color: good
text: "SUCCESS: SSAS DB Migrations in ${{ inputs.env }} (run: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.run_id }})>"
mrkdown_in:
- text
- name: Failure Alert
if: ${{ failure() }}
uses: slackapi/slack-github-action@v2.0.0
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
# Sends to bcda-alerts
payload: |
channel: "C034CFU945C"
attachments:
- color: danger
text: "FAILURE: SSAS DB Migrations in ${{ inputs.env }} (run: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.run_id }})>"
mrkdown_in:
- text

0 comments on commit cb70180

Please # to comment.