Search code examples
github-actionsprismaplanetscale

PlanetScale github flow get stuck at `prisma db push`


I have a github workflow for automating the process of create a planetscale branch and pushing the migration for review. I initially create a branch and then next step is to login to the branch db and push the schema change.

In the Run migrations step I know that the pscale connect ${{ env.PLANETSCALE_DATABASE_NAME }} ${{ env.BRANCH_NAME }} --port 3309 --org ${{ env.PLANETSCALE_ORG_NAME }} runs successfully from the logs but there is was no log for the next command DATABASE_URL=mysql://127.0.0.1:3309/${{ env.PLANETSCALE_DATABASE_NAME }}" npx prisma db push. I am not sure what the issue is and I have tried to remove the inline variable DATABASE_URL but it is still the same issue.

  - name: Create a branch
    uses: planetscale/create-branch-action@v4
    id: create_branch
    with:
      org_name: ${{ env.PLANETSCALE_ORG_NAME }}
      database_name: ${{ env.PLANETSCALE_DATABASE_NAME }}
      branch_name: ${{ env.BRANCH_NAME }}
      from: main
      check_exists: true
      wait: true
    env:
      PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }}
      PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }}

  - name: Run migrations
    run: |
      pscale connect ${{ env.PLANETSCALE_DATABASE_NAME }} ${{ env.BRANCH_NAME }} --port 3309 --org ${{ env.PLANETSCALE_ORG_NAME }}
      DATABASE_URL=mysql://127.0.0.1:3309/${{ env.PLANETSCALE_DATABASE_NAME }}" npx prisma db push
    env:
      PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }}
      PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }}

Solution

  • So the issue was that the pscale connect command waits for the connection to close and it is not existing the console after it is run. This fixes that.

      - name: Run migrations
        run: |
          pscale connect ${{ env.PLANETSCALE_DATABASE_NAME }} ${{ env.BRANCH_NAME }} --port 3309 --org ${{ env.PLANETSCALE_ORG_NAME }} &
          sleep 10
          PAYMENT_SERVICE_DATABASE_URL=mysql://127.0.0.1:3309/${{ env.PLANETSCALE_DATABASE_NAME }} npx prisma db push
          kill %1
        env:
          PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }}
          PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }}