[PR #148·150] Laying the Server Foundation First: Shared Types Out Early, Tables and Change-Blocking Triggers Built Test-First
The first task of the Detail 2 server plan was split in two and merged as two PRs. A team of Claude and other agents did the work I requested. The agents used different models, so each is listed with its role below.
- What was done:
- PR 148 (shared types): The types shared by the server, admin web and customer app got the shapes for records, photos, measurement items, schedules and inquiries. 25 new error codes and policy values such as record length and numeric upper limits were defined too. The admin module card got one required field. Five places in existing code that would break because of that field were fixed in the same commit. The real value of the field comes in a later task, so an empty value was put in for now.
- PR 150 (tables and migration): 7 entities (one table written as code) and a migration (a record of a change to the database structure) were created. The migration also holds triggers (rules the database runs automatically when a certain action happens) that block editing, deleting and emptying the rows of three tables such as record versions, and a seed (initial data) that inserts the first measurement items.
- Not done this time: services, controllers and APIs (later tasks).
- Why two PRs: Merging only the types first lets the admin web and customer app start from the same types without waiting for the server tables. So the small PR 148 was merged first on its own.
- Methods chosen and alternatives dropped:
- The migration body is exactly what the tool (
migration:generate) produced, with only the triggers and seed added by hand. Writing it all by hand could drift from the entities. - The change-blocking trigger function is one function shared by the three tables instead of one per table. The error message carries the table name.
- CHECK constraints got readable names written by hand instead of hashes.
- For the fixed sets of string values, they are written in two places instead of deriving one from the other. Deriving would have changed the existing structure, where one file does not import the other. That the two could drift apart later stayed as a low-severity note; reducing them to one source is to be considered as a follow-up.
- Numeric columns are read as numbers through a newly created converter file. It was not in the brief’s file list, but several entities share it, so it was created.
- The migration body is exactly what the tool (
Side by side, the two PRs look like this.
| PR 148 | PR 150 | |
|---|---|---|
| Built | Shared types, 25 error codes, policy values | 7 entities, a migration, change-blocking triggers, the first measurement items |
| Implementation | Claude cloud session (Fizz could not run the install) | Claude cloud session made Fizz’s 23 tests pass |
| Review | Fizz and Pollen, read-only | Fizz backend and security, Pollen general |
| Result | 414 server tests passed; 2 app tests passed on rerun | 436 of 437 server tests passed; the 1 failure was a wrong test expectation, since fixed |
Who did what
- PL (Claude Sonnet 5.5): split the work and confirmed the changed scope, the passing CI (automatic checks) and the review results.
- Claude cloud session (Claude Sonnet 5.5): implemented. In PR 148, Fizz could not run the install (
npm ci), so this session implemented that part too. PR 150 is an implementation that makes the 23 tests Fizz wrote first pass; the tests were not edited. - Fizz (GPT-6 Luna): in PR 148 did read-only review only; in PR 150 wrote the tests first and did the backend and security review.
- Pollen (OpenCode free model glm-5.3-flash-free): reviewed both PRs read-only.
How it was checked
- PR 148: the shared build, type check, lint, 167 admin web tests and 414 server tests passed. On the first run two app tests exceeded the time limit, but they were in files this PR did not touch, and running only the app tests again passed all 175. The cause was not confirmed.
- PR 150: 436 of 437 server tests passed. After applying the migrations in order to a fresh database,
migration:generateprinted “No changes in database schema were found”, which shows the entities and the migration match. - The one failure was a test that checks that emptying (TRUNCATE) the
record_versionstable is blocked. The table really was blocked, but because other tables point to it with foreign keys, PostgreSQL stopped it before reaching the trigger. So the error message was not the “append-only” text the test expected. The implementing side did not edit the test and only reported this; after the PL judged the test’s expectation to be wrong, Fizz widened that expectation in 4 lines. The part checking that the rows stay intact is unchanged. The other 13 trigger tests keep their original expectation, and CI passed afterwards.
What was not confirmed
- Rollback (
down()) drops the new tables, so it is hard to undo once real data exists. - Checks such as whether a photo and a record belong to the same module are left for the service stage to enforce.
Lessons
- Merging only the types first lets several tracks start at once. Putting the shared agreement in a small PR ahead of the rest reduces waiting.
- When the implementer reports instead of editing the tests, the tests’ own mistakes surface. This time the test’s expectation was wrong, and the implementation did not need to change.
- Run the tests once before implementing, to see whether a test itself is wrong. On the first run a missing-module error hid the individual results, and the failure above was only seen after the implementation was finished.
- In a cloud session, server tests do not run if Docker is off. Start it by hand, and if pulling an image hits the request limit (429), pull again a little later.