From 51dbbb2e45a5aa628f2f9e81dd3c688653a77881 Mon Sep 17 00:00:00 2001 From: Eric Cabrel TIOGO Date: Sun, 23 Jun 2024 14:47:52 +0200 Subject: [PATCH] build(database): target the pr branch when applying migrations --- .github/workflows/migration-db-check.yml | 11 +++++++ .github/workflows/migration-db-deploy.yml | 32 +++++-------------- .../migration.sql | 2 -- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/.github/workflows/migration-db-check.yml b/.github/workflows/migration-db-check.yml index abe7d1b2..808b389d 100644 --- a/.github/workflows/migration-db-check.yml +++ b/.github/workflows/migration-db-check.yml @@ -19,6 +19,17 @@ jobs: - name: Setup pscale uses: planetscale/setup-pscale-action@v1 + - name: Get the deploy request number in development branch + run: | + DEV_DEPLOY_REQUEST_NUMBER=$(pscale deploy-request list ${{ secrets.PLANETSCALE_DATABASE_NAME }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} -f json | jq -r '.[] | select(.into_branch == "dev" and .state == "open") | .number') + + if [ -z "$DEV_DEPLOY_REQUEST_NUMBER" ]; then + echo "No open deploy request found in the development branch." + exit 1 + fi + echo "The deploy request number in the development branch is $DEV_DEPLOY_REQUEST_NUMBER" + echo "DEV_DEPLOY_REQUEST_NUMBER=$DEV_DEPLOY_REQUEST_NUMBER" >> $GITHUB_ENV + - name: Set database branch name run: echo "PSCALE_BRANCH_NAME=$(echo ${{ github.head_ref }} | tr -cd '[:alnum:]-'| tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV diff --git a/.github/workflows/migration-db-deploy.yml b/.github/workflows/migration-db-deploy.yml index 27cb4ed7..bb54ebf6 100644 --- a/.github/workflows/migration-db-deploy.yml +++ b/.github/workflows/migration-db-deploy.yml @@ -5,32 +5,13 @@ 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 @@ -40,18 +21,21 @@ jobs: - 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 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') + DEV_DEPLOY_REQUEST_NUMBER=$(pscale deploy-request list ${{ secrets.PLANETSCALE_DATABASE_NAME }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} -f json | jq -r '.[] | select(.into_branch == "dev" and .state == "open") | .number') + + 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 - name: Check deployment state + if: ${{ env.DEV_DEPLOY_REQUEST_NUMBER != null }} continue-on-error: false run: | for i in {1..10}; do diff --git a/packages/domain/prisma/migrations/20240622222249_remove_is_favorite_in_folders_table/migration.sql b/packages/domain/prisma/migrations/20240622222249_remove_is_favorite_in_folders_table/migration.sql index ee249704..3b90ebdf 100644 --- a/packages/domain/prisma/migrations/20240622222249_remove_is_favorite_in_folders_table/migration.sql +++ b/packages/domain/prisma/migrations/20240622222249_remove_is_favorite_in_folders_table/migration.sql @@ -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`;