2024-09-28 17:42:07 -04:00
|
|
|
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
2025-06-04 12:02:07 -04:00
|
|
|
import db from "./driver";
|
2024-09-28 22:50:10 -04:00
|
|
|
import path from "path";
|
2025-07-03 21:53:07 +08:00
|
|
|
import { location } from "./driver";
|
|
|
|
import Database from "better-sqlite3";
|
|
|
|
import type { Database as BetterSqlite3Database } from "better-sqlite3";
|
2024-09-28 13:31:22 -04:00
|
|
|
|
2024-09-29 21:09:35 -04:00
|
|
|
const migrationsFolder = path.join("server/migrations");
|
2024-09-29 15:39:58 -04:00
|
|
|
|
2024-09-28 13:31:22 -04:00
|
|
|
const runMigrations = async () => {
|
2024-09-28 17:42:07 -04:00
|
|
|
console.log("Running migrations...");
|
|
|
|
try {
|
2025-07-03 21:53:07 +08:00
|
|
|
// Initialize the database file with a valid SQLite header
|
|
|
|
const sqlite = new Database(location) as BetterSqlite3Database;
|
|
|
|
sqlite.pragma('foreign_keys = ON');
|
|
|
|
|
|
|
|
// Run the migrations
|
2025-05-12 17:21:03 -04:00
|
|
|
migrate(db as any, {
|
2024-09-29 15:39:58 -04:00
|
|
|
migrationsFolder: migrationsFolder,
|
2024-09-28 22:50:10 -04:00
|
|
|
});
|
2024-09-28 17:42:07 -04:00
|
|
|
console.log("Migrations completed successfully.");
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error running migrations:", error);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2024-09-28 13:31:22 -04:00
|
|
|
};
|
|
|
|
|
2024-09-28 17:42:07 -04:00
|
|
|
runMigrations();
|