From e486c6be9fa3dd7a912bf9e1d273c2e59aafbce3 Mon Sep 17 00:00:00 2001 From: Lucas Berger Date: Thu, 11 Jun 2026 15:36:52 -0400 Subject: [PATCH] =?UTF-8?q?fix(08-03):=20seed=20dev=20user=20id=3D1=20?= =?UTF-8?q?=E2=80=94=20global-setup=20assumes=20it=20exists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit global-setup.ts seeds calendars/lists/events for user_id=1 but never creates the user (DEV_AUTH_BYPASS injects DEV_USER in-memory only). On a fresh CI DB the calendars INSERT IGNORE is silently skipped on the users FK → calendar 10 missing → calendar_events insert fails FK. Add an idempotent users(id=1) seed after migrate (validated locally: full insert chain passes). No harness files changed. --- .gitea/workflows/ci.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 312c576..1460e78 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -208,6 +208,33 @@ jobs: - name: Run DB migrations run: pnpm --filter @familysync/api db:migrate + # Seed the dev user (id=1). DEV_AUTH_BYPASS injects DEV_USER (id=1) into the request + # context in-memory only — it never writes a users row (devBypass.ts). global-setup.ts + # seeds calendars/lists/events for user_id=1 but ASSUMES that user row already exists + # (true on the dev DB, false on a fresh CI DB): without it the calendars INSERT IGNORE is + # silently skipped on the users FK, so calendar 10 is missing and the calendar_events + # insert fails its FK. Idempotent INSERT IGNORE; matches DEV_USER (oidc dev/dev-user, #4A90D9). + - name: Seed dev user (id=1) + run: | + node --input-type=commonjs - <<'EOF' + const mysql = require('mysql2/promise'); + (async () => { + const conn = await mysql.createConnection({ + host: process.env.DB_HOST, + port: Number(process.env.DB_PORT ?? 3306), + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: process.env.DB_NAME, + }); + await conn.execute( + "INSERT IGNORE INTO users (id, oidc_iss, oidc_sub, display_name, color) VALUES (1, 'dev', 'dev-user', 'Dev User', '#4A90D9')", + ); + console.log('seeded dev user id=1'); + await conn.end(); + })(); + EOF + working-directory: apps/pwa + # Build the API before starting it — dist/ is gitignored and does not exist in CI (Pitfall 4). - name: Build API run: pnpm --filter @familysync/api build