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 e67d7f1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ on:

jobs:
build:
name: Build the SvelteKit project
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

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

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

on:
workflow_call:
inputs:
environment:
description: Environment in github to target
type: string
required: true
cf_environment:
description: 'Choose an environment to deploy to: <dev|staging|prod>'
type: string
Expand All @@ -15,9 +9,7 @@ on:

jobs:
deploy:
name: Deploy to Cloudflare
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- uses: actions/download-artifact@v4
with:
Expand Down
14 changes: 10 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 @@ -8,11 +6,19 @@ on:

jobs:
build:
name: Build
uses: ./.github/workflows/build.yml
deploy:
run_migrations:
name: Run Migrations
needs: build
uses: ./.github/workflows/run_migrations.yml
secrets: inherit
with:
environment: develop
deploy:
name: Deploy to Cloudflare
needs: run_migrations
uses: ./.github/workflows/deploy.yml
secrets: inherit
with:
environment: development
cf_environment: dev
34 changes: 34 additions & 0 deletions .github/workflows/run_migrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
workflow_call:
inputs:
environment:
description: Environment in github to target
type: string
required: true

jobs:
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: 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 e67d7f1

Please sign in to comment.