Skip to content

feat: seed the http database on up - #49

Merged
jravani merged 3 commits into
mainfrom
feat/seed-on-up
Sep 29, 2026
Merged

jravani merged 3 commits into
mainfrom
feat/seed-on-up

Conversation

@jravani

@jravani jravani commented Sep 29, 2026

Copy link
Copy Markdown
Member

A bare docker compose up -d in environment/http now leaves ignis ready to serve. An empty database is seeded, a populated one is left unchanged, and a failed seed makes up fail.

build_db

Errors now stop the run. build_db discarded the error from every Exec, and a rejected insert was only logged, so it exited 0 when seeding had failed. Schema creation, drop, create, insert and the dropdown update each return an error naming the table (and the workbook row, for an insert), and build_db exits non-zero.

One transaction. The whole seed runs in a single transaction. A failure commits nothing, so the previous tables stay and no partly populated schema is ever left behind. That makes "the tabula schema holds tables" a reliable test for "a seed completed", exposed as importer.IsSeeded.

-if-empty. With the flag, build_db exits 0 without changes when the schema already holds tables. Without it, behaviour is unchanged, so make create-db still rebuilds.

environment/http

Both compose files run build-db with -if-empty on every up, and ignis depends on it with service_completed_successfully. The seed profile is removed from http, so pull fetches build-db without it.

Situation Result of up -d
empty volume seeded, then ignis starts
populated volume seed skipped, ignis starts
seed fails exit 1, service "build-db" didn't complete successfully, ignis not started

A populated database is rebuilt with docker compose run --rm build-db -if-empty=false. environment/https keeps the seed profile and its manual step. docker-compose.prod.yml needs build-db images from v0.7.0 or later; older ones reject the flag and up fails.

docs/getting-started.md and the seeder dockerfile comment describe the http and https behaviour separately.

Checks

  • New integration test TestTableConstructor_Run_failedInsert_returnsErrorAndLeavesNoTables failed on main (Run() returned nil for a row Postgres rejects) and passes here. TestIsSeeded_reportsWhetherSchemaHasTables covers the check before and after a seed.
  • go test ./..., go test -tags integration ./internal/db/, go vet ./... and mkdocs build --strict pass.
  • environment/http/docker-compose.yml run end to end under a separate project name: an empty volume seeded in 7.4 s with 2147 rows and /calculate answered; a second up skipped the seed; run --rm build-db -if-empty=false rebuilt; with a wrong DB_PASSWORD on build-db, up exited 1 and ignis stayed in Created.

build_db discarded the error from every Exec except the per-row
insert, which it only logged, so it exited 0 when the schema could
not be created, a table could not be dropped or created, or a row was
rejected. Each of these now returns an error naming the table, and for
an insert the workbook row, and build_db exits non-zero.

The whole seed runs in one transaction. A failure commits nothing, so
the previous tables stay in place and a failed seed never leaves a
partly populated schema behind. That makes "the tabula schema holds
tables" a reliable test for "a seed completed", which IsSeeded exposes.
With -if-empty, build_db checks whether the tabula schema already holds
tables and exits 0 without touching it if so. Without the flag it
drops and recreates every country table as before, so existing callers
such as `make create-db` are unchanged.
In both http compose files build-db now runs on every `up` with
-if-empty, and ignis depends on it with service_completed_successfully.
A fresh volume is seeded and ready to serve after a bare `up -d`, a
populated one is left unchanged, and a failed seed makes `up` exit 1
without starting ignis. The seed profile is removed from http, so
`pull` fetches build-db without it.

A populated database is rebuilt with
`docker compose run --rm build-db -if-empty=false`. The https
environment keeps the seed profile and its manual seed step.

The prod file needs build-db images from v0.7.0 or later; older ones
reject the -if-empty flag and `up` fails.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 48.07692% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/db/table_constructor.go 58.13% 9 Missing and 9 partials ⚠️
cmd/build_db/main.go 0.00% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

@jravani
jravani merged commit 41d8df0 into main Sep 29, 2026
6 checks passed
@jravani
jravani deleted the feat/seed-on-up branch September 29, 2026 10:24
@jravani
jravani restored the feat/seed-on-up branch September 29, 2026 10:25
@jravani
jravani deleted the feat/seed-on-up branch September 29, 2026 10:25
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.

2 participants