Skip to content

Commit

Permalink
feat: add script to migrate before building next.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ixartz committed Aug 27, 2023
1 parent f7f8743 commit 220d05e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
50 changes: 50 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "3.16.0",
"scripts": {
"dev": "next dev",
"build": "next build",
"build": "npm run db:migrate && next build",
"start": "next start",
"build-stats": "cross-env ANALYZE=true npm run build",
"clean": "rimraf .next .swc out coverage",
Expand All @@ -14,6 +14,7 @@
"commit": "cz",
"db:generate": "drizzle-kit generate:sqlite",
"db:push": "drizzle-kit push:sqlite",
"db:migrate": "tsx ./scripts/DbMigrate.ts",
"db:studio": "dotenv -c -- drizzle-kit studio",
"cypress": "cypress open",
"cypress:headless": "cypress run",
Expand Down Expand Up @@ -106,6 +107,7 @@
"start-server-and-test": "^2.0.0",
"storybook": "^7.0.27",
"tailwindcss": "^3.3.3",
"tsx": "^3.12.7",
"typescript": "^5.2.2"
},
"config": {
Expand Down
27 changes: 27 additions & 0 deletions scripts/DbMigrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable no-console */
import { createClient } from '@libsql/client';
import { drizzle } from 'drizzle-orm/libsql';
import { migrate } from 'drizzle-orm/libsql/migrator';

async function main() {
console.log('Migration started');

const client = createClient({
url: process.env.DATABASE_URL ?? '',
authToken: process.env.DATABASE_AUTH_TOKEN ?? '',
});

const db = drizzle(client);

await migrate(db, { migrationsFolder: './migrations' });

console.log('Migration completed');

process.exit(0);
}

main().catch((error) => {
console.error('Migration failed');
console.log(error);
process.exit(1);
});

0 comments on commit 220d05e

Please sign in to comment.