Trying this again...
All checks were successful
Docker Deploy / build-and-push (push) Successful in 3m48s
All checks were successful
Docker Deploy / build-and-push (push) Successful in 3m48s
This commit is contained in:
42
scripts/migrate.js
Normal file
42
scripts/migrate.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import { drizzle } from "drizzle-orm/libsql";
|
||||
import { migrate } from "drizzle-orm/libsql/migrator";
|
||||
import { createClient } from "@libsql/client";
|
||||
import path from "path";
|
||||
|
||||
async function runMigrate() {
|
||||
console.log("Running migrations...");
|
||||
|
||||
let url = process.env.DATABASE_URL;
|
||||
if (!url) {
|
||||
url = `file:${path.resolve(process.cwd(), "chronus.db")}`;
|
||||
console.log(`No DATABASE_URL found, using default: ${url}`);
|
||||
} else if (
|
||||
!url.startsWith("file:") &&
|
||||
!url.startsWith("libsql:") &&
|
||||
!url.startsWith("http:") &&
|
||||
!url.startsWith("https:")
|
||||
) {
|
||||
url = `file:${url}`;
|
||||
}
|
||||
|
||||
const authToken = process.env.DATABASE_AUTH_TOKEN;
|
||||
|
||||
const client = createClient({
|
||||
url,
|
||||
authToken,
|
||||
});
|
||||
|
||||
const db = drizzle(client);
|
||||
|
||||
try {
|
||||
await migrate(db, { migrationsFolder: "./drizzle" });
|
||||
console.log("Migrations completed successfully");
|
||||
} catch (error) {
|
||||
console.error("Migration failed:", error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
runMigrate();
|
||||
Reference in New Issue
Block a user