Merge pull request #18 from kyuno053/fix/seed-reference-data-on-deploy

fix(api): seed les données de référence (régimes/allergènes) au démarrage
This commit is contained in:
kyuno053 2026-08-18 00:06:47 +02:00 committed by GitHub
commit 1367f62f32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 3 deletions

View file

@ -42,6 +42,8 @@ COPY --from=build /repo/apps/web/dist ./apps/web/dist
WORKDIR /repo/apps/api WORKDIR /repo/apps/api
EXPOSE 3000 EXPOSE 3000
# Applies pending migrations before starting — keeps the review environment's # Applies pending migrations, then seeds the reference data (Diet/Category/
# schema in sync automatically, no manual step needed. # Allergy — see src/scripts/seed-runtime.ts) before starting. Both steps are
CMD ["sh", "-c", "node_modules/.bin/prisma migrate deploy && node dist/server.js"] # safe to repeat on every container start: migrate deploy only applies
# pending migrations, and the seed upserts by unique name.
CMD ["sh", "-c", "node_modules/.bin/prisma migrate deploy && node dist/scripts/seed-runtime.js && node dist/server.js"]

View file

@ -0,0 +1,27 @@
import { prisma } from "../db/prisma.js";
import { seedReferenceData } from "../db/reference-seed-data.js";
/**
* Runtime seed entry point for the production Docker image run via
* `node dist/scripts/seed-runtime.js` in apps/api/Dockerfile's CMD, after
* `prisma migrate deploy` and before starting the server.
*
* Deliberately separate from `prisma/seed.ts` (the dev-time entry point
* wired to `prisma db seed`/`prisma migrate reset`): that one imports
* `seedReferenceData` from `../src/db/...` and runs via `tsx`, but the
* runtime image only ships compiled `dist` output, not `src` (see the
* Dockerfile) this lives under `src/` instead, so `tsc` compiles it
* alongside everything else, and it runs under plain `node`, no tsx
* needed at runtime.
*
* Safe to run on every container start: `seedReferenceData` upserts by
* each row's unique name, so re-running it against a database that
* already has this data is a no-op.
*/
seedReferenceData(prisma)
.then(() => prisma.$disconnect())
.catch(async (err) => {
console.error(err);
await prisma.$disconnect();
process.exit(1);
});