fix(db): allow supplier CIA readings (#161) + migration-name guardrail#163
Merged
Conversation
…ype check (#161) POST /suppliers/:id/readings sets entity_type 'supplier', but the entity_readings entity_type CHECK only listed risk/legal_requirement/asset/system, so every supplier reading failed with SQLSTATE 23514. The status CHECK on the same table already carries supplier statuses — the entity_type set was simply never updated. The 0.7.1 release migration (v0.7.1.sql — one migration file per release) widens the constraint to include 'supplier'. Migration in a patch is the documented exception here: a DB CHECK constraint has no non-schema fix. Adds TestSupplierReadings covering the reported flow: create supplier -> save CIA reading -> verify classification + last_review, plus reader-role 403. Closes #161.
unidoc-alip
approved these changes
Jul 13, 2026
unidoc-alip
left a comment
Collaborator
There was a problem hiding this comment.
Correct, minimal fix for #161: the entity_readings.entity_type CHECK constraint (initial_schema.sql) never listed 'supplier', even though POST /suppliers/:id/readings has always forced entity_type = "supplier" server-side (api_readings.go:425) — confirmed by reading both. The new v0.7.1.sql migration correctly widens the constraint via DROP CONSTRAINT IF EXISTS + re-ADD, and TestSupplierReadings exercises the exact reported flow, including RBAC (reader → 403). The migration-naming guardrail (#162) is a solid filesystem-only test that all 4 existing migration files already pass. go build ./... is clean. No concerns worth blocking on.
Findings
No findings — reviewed clean.
Verification performed
- Confirmed the bug:
migrations/20260327000000_initial_schema.sql:1237definesentity_readings.entity_type CHECK (... IN ('risk','legal_requirement','asset','system'))— no'supplier', matching the reported SQLSTATE 23514. - Confirmed the write path already sends
entity_type = "supplier":internal/isms/api/api_readings.go:425(handleCreateSupplierReading), unconditionally, regardless of request body — the fix is purely schema-side as the PR claims, no handler change needed. - Confirmed
writeSupplierFromReading(api_readings.go:454-483) updatesConfidentiality/Integrity/Availability/LastReview/NextReviewon the supplier row exactly asTestSupplierReadings.test_03_supplier_updatedasserts. - Confirmed RBAC:
handleCreateSupplierReadingcallsrequireRole(c, "admin", "manager")(api_readings.go:407) — the newtest_05_reader_cannot_submit(403) is consistent with existing enforcement, not new behavior. - Ran the new naming regex (
^\d{14}_v\d+\.\d+\.\d+\.sql$) against all 4 files currently inmigrations/: all pass (2 grandfathered exactly as listed, 2 match the pattern). No spurious breakage of CI from this PR. go build ./...— clean, no errors.pytestunavailable in this environment sotests/test_migrations.py/tests/test_readings.pywere not executed live; logic was verified by static read instead.
LGTM
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.
Two related changes for 0.7.1 — closes #161 and #162.
1. Fix: supplier CIA readings (#161)
Saving a CIA reading for a Supplier failed with
entity_readings_entity_type_check(SQLSTATE 23514). The supplier reading path shipped (POST /suppliers/:id/readingsforcesentity_type = "supplier"server-side), but theentity_readingsentity_typeCHECK only listedrisk,legal_requirement,asset,system. ThestatusCHECK on the same table already carried supplier statuses — theentity_typeset was just never updated.The 0.7.1 release migration (
v0.7.1.sql— one migration file per release) widens the constraint. A migration in a patch is the documented exception: a DB CHECK constraint has no non-schema fix.DROP … IF EXISTS+ re-ADDis safe on fresh DBs too. Regression testTestSupplierReadingscovers the exact reported flow (the gap that let it ship — we had supplier review tests, not supplier reading tests).2. Guardrail: migration naming (#162)
So this can't recur:
tests/test_migrations.py(pure filesystem, no fixtures) failsjust testand CI on any migration not named<timestamp>_vX.Y.Z.sql. Grandfathersinitial_schema.sqlandchange_type_check.sql.just build-gogreen. No API/handler change — the write path was already correct.