Skip to content

Commit bb97948

Browse files
committed
chore(dev): auto-seed conformity stats fixture on dev / alpha / local
Wire the `seed-conformite-stats.mjs` script into the app startup path so /admin/stats/conformite has data to browse out of the box on every environment where it is useful: - `entrypoint.sh` runs the seed after Drizzle migrations when `EGAPRO_AUTO_SEED_CONFORMITE=true`. Failure is non-fatal — the app still boots; we just log a warning. - `Dockerfile` copies the seed script next to the other runtime scripts (migrate, audit-cleanup) so it's available to the runner image. - `.kontinuous/env/dev/values.yaml` turns the flag on. This covers review apps (including the alpha branch) but leaves preprod and prod untouched — they keep running on real data. - Locally, `pnpm dev` chains the seed before `next dev` (idempotent upserts + `|| true` fallback so a missing DB never blocks the dev server). Also fixes a leftover bug in the seed script where `CAMPAIGN_YEARS_BACK` was referenced but not defined — restores the 4-year window.
1 parent 175a51a commit bb97948

5 files changed

Lines changed: 24 additions & 7 deletions

File tree

.kontinuous/env/dev/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
app:
22
annotations:
33
oblik.socialgouv.io/min-limit-cpu: 2
4+
vars:
5+
# Seed the admin conformity-stats fixture at container startup so every
6+
# review app (including alpha) has realistic numbers to browse. Gated
7+
# here so preprod / prod never auto-seed — they ship with real data.
8+
EGAPRO_AUTO_SEED_CONFORMITE: "true"

packages/app/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ COPY --from=builder --chown=1000:1000 /app/packages/app/scripts/migrate.mjs ./pa
8080
# Standalone script invoked by the audit-cleanup CronJob (issue #3268 — direct
8181
# DB access replaces the former curl → /api/audit/cleanup HTTP trigger).
8282
COPY --from=builder --chown=1000:1000 /app/packages/app/scripts/audit-cleanup.mjs ./packages/app/scripts/audit-cleanup.mjs
83+
# Optional conformity-stats fixture seed (dev / alpha review apps only;
84+
# gated by EGAPRO_AUTO_SEED_CONFORMITE in entrypoint.sh).
85+
COPY --from=builder --chown=1000:1000 /app/packages/app/scripts/seed-conformite-stats.mjs ./packages/app/scripts/seed-conformite-stats.mjs
8386

8487
USER 1000
8588

packages/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"db:migrate": "drizzle-kit migrate",
1717
"db:push": "drizzle-kit push",
1818
"db:studio": "drizzle-kit studio",
19-
"dev": "node scripts/copy-dsfr.mjs && node scripts/copy-swagger-ui.mjs && next dev --turbo",
19+
"dev": "node scripts/copy-dsfr.mjs && node scripts/copy-swagger-ui.mjs && (pnpm seed:conformite || true) && next dev --turbo",
2020
"preview": "next build && next start",
2121
"start": "next start",
2222
"test": "vitest run",

packages/app/scripts/entrypoint.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,18 @@ echo "Running Drizzle migrations..."
55
node packages/app/scripts/migrate.mjs
66
echo "Migrations completed."
77

8+
# Opt-in fixture seeding for the admin conformity stats page. Enabled only
9+
# on dev/alpha review apps via .kontinuous/env/dev/values.yaml — never on
10+
# preprod or prod. Idempotent upserts, so re-running on every pod restart
11+
# is safe. Failure is treated as non-fatal: the app still boots.
12+
if [ "$EGAPRO_AUTO_SEED_CONFORMITE" = "true" ]; then
13+
echo "Seeding admin conformity fixture (EGAPRO_AUTO_SEED_CONFORMITE=true)..."
14+
if node packages/app/scripts/seed-conformite-stats.mjs; then
15+
echo "Conformity fixture seeded."
16+
else
17+
echo "WARNING: conformity seed failed, continuing startup anyway." >&2
18+
fi
19+
fi
20+
821
echo "Starting Next.js..."
922
exec node packages/app/server.js

packages/app/scripts/seed-conformite-stats.mjs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ const NAF_SAMPLE_CODES = [
3737
"M70.10Z", // M — Activités spécialisées
3838
"Q86.10Z", // Q — Santé humaine
3939
];
40-
/**
41-
* Kept in sync with `FIRST_DECLARATION_YEAR` from `~/modules/domain` — the
42-
* year filter on `/admin/stats/conformite` goes from there to the current
43-
* year, so we seed every slot to avoid empty tiles on older selections.
44-
*/
45-
const FIRST_SEED_YEAR = 2019;
40+
/** Number of most-recent campaign years to seed (current year + N-1 … N-3). */
41+
const CAMPAIGN_YEARS_BACK = 4;
4642

4743
function getDatabaseUrl() {
4844
if (process.env.DATABASE_URL) return process.env.DATABASE_URL;

0 commit comments

Comments
 (0)