Skip to content

Instantly share code, notes, and snippets.

@TeemuKoivisto
Created May 10, 2022 06:06
Show Gist options
  • Save TeemuKoivisto/3e6378dd0e2cf0a7496a7563e2694b4e to your computer and use it in GitHub Desktop.
Save TeemuKoivisto/3e6378dd0e2cf0a7496a7563e2694b4e to your computer and use it in GitHub Desktop.
Github action to migrate Postgres DB in Heroku with pnpm and Prisma
name: Migrate Heroku DB
on:
push:
branches:
- main
workflow_dispatch:
inputs:
run_seed:
description: 'Run post migrate operation: <none> | seed'
required: false
default: 'seed'
env:
PNPM_CACHE_FOLDER: .pnpm-store
jobs:
deployment:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node_version }}
- name: Cache pnpm dependencies
uses: actions/cache@v2
with:
path: ${{ env.PNPM_CACHE_FOLDER }}
key: ${{ runner.os }}-node${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-
- name: Install pnpm
run: curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@6
- name: Install dependencies
run: pnpm i --frozen-lockfile --filter @my-app/db
- name: Run the migrations
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: pnpm run prod:migrate --filter @my-app/db
- name: Seed the DB
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
if: github.event.inputs.run_seed == 'seed'
run: |
pnpm run generate --filter @my-app/db
pnpm run seed --filter @my-app/db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment