Skip to content

Commit

Permalink
feat: do not run db migration when building on GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ixartz committed Aug 27, 2023
1 parent 3f489d4 commit 964cfa1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
name: Build with ${{ matrix.node-version }}
runs-on: ubuntu-latest

env:
MIGRATE_DB: true

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
6 changes: 2 additions & 4 deletions src/libs/DB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import { createClient } from '@libsql/client';
import { drizzle } from 'drizzle-orm/libsql';
import { migrate } from 'drizzle-orm/libsql/migrator';

import * as schema from '@/models/Schema';

import { Env } from './Env.mjs';

const client = createClient({
url: Env.DATABASE_URL,
authToken: Env.DATABASE_AUTH_TOKEN,
});

export const db = drizzle(client, { schema });
export const db = drizzle(client);

if (Env.NODE_ENV !== 'production') {
if (Env.NODE_ENV !== 'production' || Env.MIGRATE_DB) {
await migrate(db, { migrationsFolder: './migrations' });
}
2 changes: 2 additions & 0 deletions src/libs/Env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const Env = createEnv({
CLERK_SECRET_KEY: z.string().nonempty(),
DATABASE_URL: z.string().nonempty(),
DATABASE_AUTH_TOKEN: z.string().optional(),
MIGRATE_DB: z.coerce.boolean().optional(),
},
client: {
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().nonempty(),
Expand All @@ -23,6 +24,7 @@ export const Env = createEnv({
NODE_ENV: process.env.NODE_ENV,
DATABASE_URL: process.env.DATABASE_URL,
DATABASE_AUTH_TOKEN: process.env.DATABASE_AUTH_TOKEN,
MIGRATE_DB: process.env.MIGRATE_DB,
CLERK_SECRET_KEY: process.env.CLERK_SECRET_KEY,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY:
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
Expand Down

0 comments on commit 964cfa1

Please sign in to comment.