Skip to content

Add 'Branch' type to entry. Enforce only one Consortium per db. Enfor… - #31

Merged
kurtnordstrom merged 5 commits into
mainfrom
entry-branches
Jul 14, 2026
Merged

Add 'Branch' type to entry. Enforce only one Consortium per db. Enfor…#31
kurtnordstrom merged 5 commits into
mainfrom
entry-branches

Conversation

@kurtnordstrom

Copy link
Copy Markdown
Contributor

…ce parent entries for types

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread api/entries.go Outdated
Comment thread test/entries_test.go
Comment thread test/entries_test.go
Comment thread test/entries_test.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • db/query.sql.go: Generated file

Comment thread api/entries.go
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
kurtnordstrom marked this pull request as ready for review July 14, 2026 14:48
@kurtnordstrom
kurtnordstrom merged commit 000bd34 into main Jul 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants