Repository navigation
feat: seed the http database on up - #49
Merged
Merged
Conversation
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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A bare
docker compose up -dinenvironment/httpnow leaves ignis ready to serve. An empty database is seeded, a populated one is left unchanged, and a failed seed makesupfail.build_db
Errors now stop the run.
build_dbdiscarded the error from everyExec, 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), andbuild_dbexits 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
tabulaschema holds tables" a reliable test for "a seed completed", exposed asimporter.IsSeeded.-if-empty. With the flag,build_dbexits 0 without changes when the schema already holds tables. Without it, behaviour is unchanged, somake create-dbstill rebuilds.environment/http
Both compose files run
build-dbwith-if-emptyon everyup, andignisdepends on it withservice_completed_successfully. Theseedprofile is removed from http, sopullfetchesbuild-dbwithout it.up -dservice "build-db" didn't complete successfully, ignis not startedA populated database is rebuilt with
docker compose run --rm build-db -if-empty=false.environment/httpskeeps theseedprofile and its manual step.docker-compose.prod.ymlneedsbuild-dbimages from v0.7.0 or later; older ones reject the flag andupfails.docs/getting-started.mdand the seeder dockerfile comment describe the http and https behaviour separately.Checks
TestTableConstructor_Run_failedInsert_returnsErrorAndLeavesNoTablesfailed onmain(Run() returned nil for a row Postgres rejects) and passes here.TestIsSeeded_reportsWhetherSchemaHasTablescovers the check before and after a seed.go test ./...,go test -tags integration ./internal/db/,go vet ./...andmkdocs build --strictpass.environment/http/docker-compose.ymlrun end to end under a separate project name: an empty volume seeded in 7.4 s with 2147 rows and/calculateanswered; a secondupskipped the seed;run --rm build-db -if-empty=falserebuilt; with a wrongDB_PASSWORDonbuild-db,upexited 1 andignisstayed inCreated.