53 lines
1.5 KiB
YAML

name: Workflow for prisma migrations
on:
workflow_call:
inputs:
PROD_PRISMA_SECRET_DB_PATH:
required: true
type: string
description: Prisma db url secret path in vault for prod
DEV_PRISMA_SECRET_DB_PATH:
required: true
type: string
description: Prisma db url secret path in vault for dev
secrets:
VAULT_TOKEN:
required: true
jobs:
migration:
runs-on: ubuntu-latest
container:
image: catthehacker/ubuntu:act-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
- name: Install dependencies
run: npm install
- name: Export secrets for prisma
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "PRISMA_DB_SECRET_PATH=${{ inputs.PROD_PRISMA_SECRET_DB_PATH }}" >> $GITHUB_ENV
else
echo "PRISMA_DB_SECRET_PATH=${{ inputs.DEV_PRISMA_SECRET_DB_PATH }}" >> $GITHUB_ENV
fi
- name: Import prisma db url
uses: hashicorp/vault-action@v2
with:
url: https://vault.project-rent-dev.com
token: ${{ secrets.VAULT_TOKEN }}
secrets: |
${{ env.PRISMA_DB_SECRET_PATH }} | PRISMA_DB_URL;
- name: Apply all pending migrations to the database
run: npx prisma migrate deploy
env:
DATABASE_URL: ${{ env.PRISMA_DB_URL }}