From e67d7f1fd508ab55fc2676db2f4f067ac897206d Mon Sep 17 00:00:00 2001 From: Jeroen Pelgrims Date: Tue, 6 Feb 2024 15:06:14 +0100 Subject: [PATCH] Add migrations step --- .github/workflows/build.yml | 3 +-- .github/workflows/deploy.yml | 8 ------- .github/workflows/development.yml | 14 ++++++++---- .github/workflows/run_migrations.yml | 34 ++++++++++++++++++++++++++++ drizzle/migrate.ts | 10 ++++++-- 5 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/run_migrations.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4e8d253..9c64b51 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 981474e..cc4874c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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: ' type: string @@ -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: diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index 6ca44aa..773ee69 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -1,5 +1,3 @@ -name: Development actions - on: push: branches: @@ -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 diff --git a/.github/workflows/run_migrations.yml b/.github/workflows/run_migrations.yml new file mode 100644 index 0000000..38f72fd --- /dev/null +++ b/.github/workflows/run_migrations.yml @@ -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/action-setup@v2.4.0 + 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 diff --git a/drizzle/migrate.ts b/drizzle/migrate.ts index 689310e..c8757c9 100644 --- a/drizzle/migrate.ts +++ b/drizzle/migrate.ts @@ -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();