chore(database): move from planetsacle to rds sniff #38
Workflow file for this run
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: Check database migration | |
on: | |
pull_request: | |
branches: | |
- 'main' | |
paths: | |
- 'packages/domain/prisma/migrations/**' | |
jobs: | |
migration-detail: | |
runs-on: ubuntu-latest | |
env: | |
MYSQL_ROOT_PASSWORD: root | |
MYSQL_DATABASE: db | |
MYSQL_PORT: 3306 | |
DATABASE_URL: mysql://root:[email protected]:3306/db | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Start MySQL server | |
run: sudo systemctl start mysql.service | |
- name: Install dependencies | |
uses: ./.github/actions/install-dependencies | |
- name: Run migrations | |
run: yarn workspace @snipcode/domain db:migrate | |
- name: Install Doppler CLI | |
uses: dopplerhq/cli-action@v3 | |
- name: Retrieve and export the production database URL | |
run: echo "PROD_DATABASE_URL=$(doppler secrets get CONNECTION_STRING --plain)" >> $GITHUB_ENV | |
env: | |
DOPPLER_TOKEN: ${{ secrets.DOPPLER_DATABASE_TOKEN }} | |
- name: Collect the migration diff | |
continue-on-error: false | |
working-directory: packages/domain | |
run: | | |
set -e | |
echo "### Database Migration Detected" > migration-message.txt | |
echo "The following migration will be applied to the production database:" >> migration-message.txt | |
echo "" >> migration-message.txt | |
echo "\`\`\`sql" >> migration-message.txt | |
yarn prisma migrate diff --from-url "$PROD_DATABASE_URL" --to-url "$DATABASE_URL" --script >> migration-message.txt | |
echo "\`\`\`" >> migration-message.txt | |
echo "" >> migration-message.txt | |
echo "" >> migration-message.txt | |
echo "Please ensure your schema changes are compatible with the application code currently running in production." >> migration-message.txt | |
# - name: Comment pull request with the migration diff | |
# uses: thollander/actions-comment-pull-request@v2 | |
# with: | |
# filePath: packages/domain/migration-message.txt | |
- name: Create or update the pull request with the migration diff | |
uses: actions/github-script@v6 | |
id: plan-comment | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const { data: comments } = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
}); | |
const botComment = comments.find(comment => { | |
return comment.user.type === 'Bot' && comment.body.includes('Database Migration Detected') | |
}); | |
const output = fs.readFileSync('packages/domain/migration-message.txt', 'utf8'); | |
if (botComment) { | |
github.rest.issues.deleteComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: botComment.id, | |
}); | |
} | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: output | |
}); |