costco-grocery-list/scripts/db-migrate.js
Nico 77ae5be445
All checks were successful
Build & Deploy Costco Grocery List / build (push) Successful in 1m10s
Build & Deploy Costco Grocery List / verify-images (push) Successful in 3s
Build & Deploy Costco Grocery List / deploy (push) Successful in 11s
Build & Deploy Costco Grocery List / notify (push) Successful in 1s
refactor
2026-02-22 01:27:03 -08:00

53 lines
1.2 KiB
JavaScript

"use strict";
const {
applyMigration,
ensureDatabaseUrl,
ensurePsql,
ensureSchemaMigrationsTable,
getAppliedMigrations,
getMigrationFiles,
} = require("./db-migrate-common");
function main() {
if (process.argv.includes("--help")) {
console.log("Usage: npm run db:migrate");
process.exit(0);
}
const migrateDisabled = String(process.env.DB_MIGRATE_DISABLE || "")
.trim()
.toLowerCase();
if (migrateDisabled === "1" || migrateDisabled === "true" || migrateDisabled === "yes") {
console.log("DB migrations are disabled by DB_MIGRATE_DISABLE. Skipping.");
return;
}
const databaseUrl = ensureDatabaseUrl();
ensurePsql();
ensureSchemaMigrationsTable(databaseUrl);
const files = getMigrationFiles();
const applied = getAppliedMigrations(databaseUrl);
const pending = files.filter((file) => !applied.has(file));
if (pending.length === 0) {
console.log("No pending migrations.");
return;
}
for (const file of pending) {
console.log(`Applying: ${file}`);
applyMigration(databaseUrl, file);
}
console.log(`Applied ${pending.length} migration(s).`);
}
try {
main();
} catch (error) {
console.error(error.message);
process.exit(1);
}