Files
portfolio/scripts/start-with-migrate.js
2026-01-12 15:08:23 +00:00

41 lines
1.1 KiB
JavaScript

/**
* Container entrypoint: apply Prisma migrations, then start Next server.
*
* Why:
* - In real deployments you want schema changes applied automatically per deploy.
* - `prisma migrate deploy` is safe to run multiple times (idempotent).
*
* Controls:
* - Set `SKIP_PRISMA_MIGRATE=true` to skip migrations (emergency / debugging).
*/
const { spawnSync } = require("node:child_process");
function run(cmd, args, opts = {}) {
const res = spawnSync(cmd, args, {
stdio: "inherit",
env: process.env,
...opts,
});
if (res.error) {
throw res.error;
}
if (typeof res.status === "number" && res.status !== 0) {
// propagate exit code
process.exit(res.status);
}
}
const skip = String(process.env.SKIP_PRISMA_MIGRATE || "").toLowerCase() === "true";
if (!skip) {
// Avoid relying on `npx` resolution in minimal runtimes.
// We copy `node_modules/prisma` into the runtime image.
run("node", ["node_modules/prisma/build/index.js", "migrate", "deploy"]);
} else {
// eslint-disable-next-line no-console
console.log("SKIP_PRISMA_MIGRATE=true -> skipping prisma migrate deploy");
}
run("node", ["server.js"]);