Skip to content

fix(docker): make empty-database setup work in the production image - #30

Merged
teo-goulois merged 1 commit into
mainfrom
fix/docker-empty-db-setup
Jul 9, 2026
Merged

fix(docker): make empty-database setup work in the production image#30
teo-goulois merged 1 commit into
mainfrom
fix/docker-empty-db-setup

Conversation

@teo-goulois

Copy link
Copy Markdown
Contributor

Problem

Running the published Docker image against an empty MySQL fails to create any tables (#28). setupDatabase() shelled out to npx drizzle-kit push, but drizzle-kit and its config are dev-only and absent from the pruned standalone image. The error was then swallowed, so the app booted into a silently broken state.

Fixes

  • setupDatabase() runs the committed SQL migrations programmatically via a shared runMigrations() (packages/db), with connection retries and a guard against foreign databases. On failure it now exits non-zero — visible crash loop instead of a broken "running" app.
  • Migrations are bundled into the app image (/app/migrations + MIGRATIONS_FOLDER).
  • /api/health returns 503 until the core tables exist, so the existing Docker healthcheck reflects real readiness.
  • New CI smoke-test job builds the image, boots it against an empty MySQL 8.4, waits for health 200 and asserts the core tables exist. It gates the registry push on tags and runs on PRs touching docker/db files — this is the guard that would have caught Louez - Docker "no tables created" #28 before release.

Latent bugs surfaced by the smoke test (also fixed)

  • migrate.ts queried __drizzle_migrations before creating it — the empty-database path had never worked.
  • Migrations 0032/0034 contain multiple statements without --> statement-breakpoint; migrator connections now enable multipleStatements (migration files untouched, hashes preserved).
  • .dockerignore patterns only matched at the repo root: nested .next and the multi-GB .turbo cache were shipped in the build context.
  • public/ was copied without --chown, crashing the non-root app when build-host permissions were restrictive.

Verification

Full smoke test run locally on the production image (Colima): empty MySQL 8.4 → 53 migrations applied, 62 tables created, /api/health 200, Docker healthcheck healthy, restart idempotent ("Database is up to date"). Typecheck passes on packages/db and apps/web.

Fixes #28

🤖 Generated with Claude Code

The Docker image failed to initialize an empty database (#28):
setupDatabase() shelled out to `npx drizzle-kit push`, but drizzle-kit and
its config are dev-only and absent from the pruned standalone image. The
failure was then swallowed and the app booted in a broken state.

Fixes:
- setupDatabase() now runs the committed SQL migrations programmatically
  (shared runMigrations() from packages/db), with connection retries and a
  guard against foreign databases; on failure it exits non-zero so the
  container crash-loops visibly instead of serving a broken app
- bundle packages/db migrations into the app image (MIGRATIONS_FOLDER)
- /api/health now returns 503 until the core tables exist, so the Docker
  healthcheck reflects real readiness
- CI: new smoke-test job boots the image against an empty MySQL, waits for
  health 200 and asserts core tables exist; it gates the registry push

Latent bugs surfaced by the smoke test, also fixed:
- migrate.ts queried __drizzle_migrations before creating it (empty-DB path
  never worked)
- migrations 0032/0034 hold several statements without statement-breakpoint
  markers; migrator connections now enable multipleStatements
- .dockerignore patterns only matched at the repo root: nested .next and
  the 24GB .turbo cache were shipped in the build context
- public/ was copied without --chown, crashing the non-root app when build
  host permissions were restrictive

Fixes #28

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@teo-goulois
teo-goulois merged commit 055418f into main Jul 9, 2026
2 checks passed
@teo-goulois
teo-goulois deleted the fix/docker-empty-db-setup branch July 9, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Louez - Docker "no tables created"

1 participant