23 lines
862 B
JavaScript
23 lines
862 B
JavaScript
import db from "../src/inc/sql.mjs";
|
|
import { promises as fs } from "fs";
|
|
|
|
(async () => {
|
|
try {
|
|
const migration = await fs.readFile("./migration_comments.sql", "utf-8");
|
|
console.log("Applying migration...");
|
|
// Split by semicolon to handle multiple statements if the driver requires it,
|
|
// but postgres.js usually handles simple files well or we can execute as one block
|
|
// if it's just DDL. However, postgres.js template literal usually prefers single statements
|
|
// or we can use `db.file` if available, or just execute the string.
|
|
|
|
// Simple approach: execute the whole string
|
|
await db.unsafe(migration);
|
|
|
|
console.log("Migration applied successfully.");
|
|
process.exit(0);
|
|
} catch (e) {
|
|
console.error("Migration failed:", e);
|
|
process.exit(1);
|
|
}
|
|
})();
|