Skip to content

Commit

Permalink
Add migrations step
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenpelgrims committed Feb 7, 2024
1 parent 93bb1e2 commit f7f2088
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18

Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
name: Deploy

on:
workflow_call:
inputs:
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
name: Development actions

on:
push:
branches:
Expand All @@ -9,10 +7,16 @@ on:
jobs:
build:
uses: ./.github/workflows/build.yml
deploy:
run_migrations:
needs: build
uses: ./.github/workflows/run_migrations.yml
secrets: inherit
with:
environment: develop
deploy:
needs: run_migrations
uses: ./.github/workflows/deploy.yml
secrets: inherit
with:
environment: development
environment: develop
cf_environment: dev
41 changes: 41 additions & 0 deletions .github/workflows/run_migrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
on:
workflow_call:
inputs:
environment:
description: Environment in github to target
type: string
required: true

jobs:
build:
name: Run migrations
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Setup pnpm
uses: pnpm/[email protected]
with:
version: 8

- name: Install dependencies
run: pnpm install

- name: Debug
env:
TURSO_DB_URL: ${{ secrets.TURSO_DB_URL }}
TURSO_DB_AUTH_TOKEN: ${{ secrets.TURSO_DB_AUTH_TOKEN }}
run: echo "TURSO_DB_URL=$TURSO_DB_URL"

- name: Run migrations
env:
TURSO_DB_URL: ${{ secrets.TURSO_DB_URL }}
TURSO_DB_AUTH_TOKEN: ${{ secrets.TURSO_DB_AUTH_TOKEN }}
run: pnpm run migrations:run
10 changes: 8 additions & 2 deletions drizzle/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { createClient } from '@libsql/client';
import 'dotenv/config';
import { drizzle } from 'drizzle-orm/libsql/driver';
import { migrate } from 'drizzle-orm/libsql/migrator';
import { client, connect } from '../src/lib/db/index';
import * as schema from '../src/lib/db/schema';

const db = connect();
const client = createClient({
url: process.env.TURSO_DB_URL ?? '',
authToken: process.env.TURSO_DB_AUTH_TOKEN,
});
const db = drizzle(client, { schema });
await migrate(db, { migrationsFolder: './drizzle/migrations' });
client.close();

0 comments on commit f7f2088

Please sign in to comment.