release: WRNexusJS 0.8.0
This commit is contained in:
+30
-1
@@ -20,6 +20,8 @@ import { pathToFileURL } from "node:url";
|
||||
import { loadAppConfig, type AppConfig } from "@wrnexus/styles";
|
||||
import {
|
||||
generateQueriesFile,
|
||||
analyzeMigrations,
|
||||
loadMigrations,
|
||||
migrate,
|
||||
parseQueries,
|
||||
rollback,
|
||||
@@ -125,6 +127,18 @@ export async function runDbCommand(
|
||||
const dbBase = dbBaseOf(appDir, dbName);
|
||||
const migrationsDir = join(dbBase, "migrations");
|
||||
const label = dbName ? ` (db: ${dbName})` : "";
|
||||
const safetyIssues = analyzeMigrations(loadMigrations(migrationsDir));
|
||||
|
||||
if (sub === "check") {
|
||||
if (!safetyIssues.length) console.log(`✓ Migration rollout safety check passed${label}.`);
|
||||
for (const issue of safetyIssues) {
|
||||
console[issue.severity === "error" ? "error" : "warn"](
|
||||
`${issue.code} ${issue.migration}: ${issue.statement}\n ${issue.recommendation}`,
|
||||
);
|
||||
}
|
||||
if (safetyIssues.some((issue) => issue.severity === "error")) process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (dbName && !config.databases?.[dbName]) {
|
||||
console.error(
|
||||
@@ -213,6 +227,21 @@ export async function runDbCommand(
|
||||
break;
|
||||
}
|
||||
case "migrate": {
|
||||
const pending = new Set(
|
||||
(await status(db, migrationsDir))
|
||||
.filter((migration) => !migration.applied)
|
||||
.map((migration) => migration.name),
|
||||
);
|
||||
const pendingIssues = safetyIssues.filter((issue) => pending.has(issue.migration));
|
||||
const blockers = pendingIssues.filter((issue) => issue.severity === "error");
|
||||
for (const issue of pendingIssues.filter((item) => item.severity === "warning")) {
|
||||
console.warn(`${issue.code} ${issue.migration}: ${issue.recommendation}`);
|
||||
}
|
||||
if (blockers.length && !args.includes("--allow-breaking")) {
|
||||
throw new Error(
|
||||
`WRN-DB-UNSAFE-MIGRATION: ${blockers.length} breaking rollout operation(s) found. Run 'wrnexus db check' and use an expand/contract migration; --allow-breaking explicitly overrides this gate.`,
|
||||
);
|
||||
}
|
||||
const applied = await migrate(db, migrationsDir);
|
||||
console.log(
|
||||
applied.length
|
||||
@@ -234,7 +263,7 @@ export async function runDbCommand(
|
||||
}
|
||||
default:
|
||||
console.error(
|
||||
"Usage: wrnexus db <migrate|rollback|status|generate|seed|studio [table]|new [name] [--from-models]> [--db=<name>]",
|
||||
"Usage: wrnexus db <check|migrate|rollback|status|generate|seed|studio [table]|new [name] [--from-models]> [--db=<name>]",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user