All checks were successful
Docker Deploy / build-and-push (push) Successful in 3m48s
43 lines
1014 B
JavaScript
43 lines
1014 B
JavaScript
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();
|