Refactor Docker entrypoint to run Prisma migrations; update schema
Co-authored-by: dennis <dennis@konkol.net>
This commit is contained in:
40
scripts/start-with-migrate.js
Normal file
40
scripts/start-with-migrate.js
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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"]);
|
||||
|
||||
Reference in New Issue
Block a user