Add 'Branch' type to entry. Enforce only one Consortium per db. Enfor… - #31
Merged
Conversation
…ce parent entries for types
There was a problem hiding this comment.
Pull request overview
This PR extends the Entries API/data model to support stricter entry-type relationships (including a new Branch type), and enforces a “single Consortium per DB” invariant with concurrency-safe locking to prevent races.
Changes:
- Add parent/type validation rules (Institution parent must be Consortium; Branch parent must be Institution) on create/update, and prevent invalid type changes when existing children would become invalid.
- Enforce “only one Consortium entry” using a transaction-scoped advisory lock plus an existence check, including concurrent test coverage.
- Add new SQL queries (get consortium, list children by parent, lock helper) and generated sqlc bindings.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
api/entries.go |
Adds parent/type validation, child-invariant enforcement on type change, and consortium uniqueness enforcement with advisory locking. |
query.sql |
Introduces queries for consortial entry lookup, children-by-parent lookup, and advisory locking. |
db/query.sql.go |
sqlc-generated bindings for the new queries. |
test/entries_test.go |
Adds new integration cases for parent/type validation and consortium uniqueness; fixes one typo in a test name. |
test/concurrency_test.go |
Adds concurrent POST/PATCH tests to ensure only one Consortium can be created/promoted under race. |
Files not reviewed (1)
- db/query.sql.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+751
to
+755
| if resultingType == "Consortium" && resultingType != orig.Type { | ||
| consortialEntry, err := qtx.GetConsortialEntry(ctx) | ||
| if err == nil && consortialEntry.ID != orig.ID { | ||
| return UpdateEntry400TextResponse("An entry of type Consortium already exists"), nil | ||
| } else if err != nil && !errors.Is(err, pgx.ErrNoRows) { |
kurtnordstrom
marked this pull request as ready for review
July 14, 2026 14:48
kurtnordstrom
requested review from
adamdickmeiss,
ihardy,
jakub-id and
skomorokh
as code owners
July 14, 2026 14:48
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.
…ce parent entries for types