forked from ocluf/justship
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate.ts
39 lines (32 loc) · 956 Bytes
/
migrate.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as dotenv from "dotenv";
import { createClient } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";
import { migrate } from "drizzle-orm/libsql/migrator";
// Load environment variables from .env file
dotenv.config();
// Get the command-line arguments
const args = process.argv.slice(2);
const isProd = args.includes("--prod");
// Determine the database URL based on the argument
const dbUrl = isProd ? process.env.TURSO_DB_URL : "file:local.db";
if (!dbUrl) {
throw new Error("Database URL not provided");
}
// Create the database client
const dbClient = createClient({
url: dbUrl,
authToken: process.env.TURSO_DB_AUTH_TOKEN as string,
});
// Create the drizzle client
const drizzleClient = drizzle(dbClient);
// Run the migration
migrate(drizzleClient, {
migrationsFolder: "./drizzle",
})
.then(() => {
console.log("Migrations completed");
process.exit(0);
})
.catch((err) => {
throw err;
});