Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(database): target the pr branch when applying migrations #78

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 10 additions & 29 deletions .github/workflows/migration-db-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,32 @@ on:
- 'main'
paths:
- 'packages/domain/prisma/migrations/**'
pull_request:
branches:
- 'main'
paths:
- 'packages/domain/prisma/migrations/**'

env:
PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }}
PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }}

jobs:
print-branch-name:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Print pull request branch
if: github.event_name == 'pull_request'
run: |
echo "Pull Request Branch: ${{ github.event.pull_request.head.ref }}"

apply-migration:
# run only the push event on the main branch
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup pscale
uses: planetscale/setup-pscale-action@v1

- name: Set database branch name
run: |
echo "Name 1: ${{ github.ref }}"
echo "Name 2: ${{ github.ref_name }}"
echo "Name 3: ${{ github.ref_type }}"
echo "Name 4: ${{ github }}"
echo "PSCALE_BRANCH_NAME=$(echo ${{ github.event.pull_request.base.ref }} | tr -cd '[:alnum:]-'| tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Get the deploy request number in development branch
- name: Get the deploy request number and branch name in development branch
run: |
DEV_DEPLOY_REQUEST_NUMBER=$(pscale deploy-request show ${{ secrets.PLANETSCALE_DATABASE_NAME }} ${{ env.PSCALE_BRANCH_NAME }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} -f json | jq -r '.number')
DEPLOYER_REQUEST_LIST=$(pscale deploy-request list ${{ secrets.PLANETSCALE_DATABASE_NAME }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} -f json)
DEV_DEPLOY_REQUEST_NUMBER=$(echo "$DEPLOYER_REQUEST_LIST" | jq -r '.[] | select(.into_branch == "dev" and .state == "open") | .number')
PSCALE_BRANCH_NAME=$(echo "$DEPLOYER_REQUEST_LIST" | jq -r '.[] | select(.into_branch == "dev" and .state == "open") | .branch')

if [ -z "$DEV_DEPLOY_REQUEST_NUMBER" ]; then
echo "No open deploy request found in the development branch."
exit 1
fi
echo "DEV_DEPLOY_REQUEST_NUMBER=$DEV_DEPLOY_REQUEST_NUMBER" >> $GITHUB_ENV
echo "PSCALE_BRANCH_NAME=$PSCALE_BRANCH_NAME" >> $GITHUB_ENV

- name: Check deployment state
continue-on-error: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/*

Warnings:
- You are about to drop the column `is_favorite` on the `folders` table. All the data in the column will be lost.

*/
-- DropIndex
DROP INDEX `folders_is_favorite_idx` ON `folders`;
Expand Down
Loading