Skip to content

Commit 925238e

Browse files
nshkiCopilot
andcommitted
test(hub): cover Build number constraint
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b60c01ad-40e3-4341-a27c-c1bff63a1ff0
1 parent c44ef07 commit 925238e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎hub/docs/database.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Keep ordinary value and shape validation in application code. Add a database gua
7676

7777
For prototypes, one active branch has one identity per repository, including concurrent writes. Retired branches keep their history. A registered prototype must have a nonblank name and cannot be a replica branch.
7878

79+
A Build number is positive and unique within its prototype. A prototype's current Build, if set, belongs to that prototype.
80+
7981
PostgreSQL `CHECK` expressions accept `NULL` unless the expression explicitly rejects it. Write nullable-branch checks so every invalid `NULL` combination evaluates to false. Design indexes from the real equality, range, ordering, and partial predicates used by lock, restore, and lookup queries.
8082

8183
Validate schema changes on both a fresh database and an upgrade from the exact base. Migration tests should seed representative base records and prove required data, backfills, relationships, and constraints after deployment. Do not enumerate the complete migration, table, column, or index inventory. Split PostgreSQL enum additions from statements that use the new values when transactional enum visibility requires a committed boundary.

‎hub/test/database/prototype-build-status-migration/index.db.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const migrationTestTimeoutMs = 60_000
1111

1212
describe("prototype Build status migration", () => {
1313
it(
14-
"preserves prototypes and enforces Build ownership after an upgrade",
14+
"preserves prototypes and protects Build numbers and ownership",
1515
async () => {
1616
const adminUrl = process.env.TEST_DATABASE_URL
1717
if (!adminUrl) throw new Error("TEST_DATABASE_URL is required.")
@@ -113,6 +113,13 @@ describe("prototype Build status migration", () => {
113113
])
114114

115115
const buildId = randomUUID()
116+
await expect(
117+
database.query(
118+
`INSERT INTO builds (id, prototype_id, number, state)
119+
VALUES ($1, $2, 0, 'successful')`,
120+
[buildId, firstPrototypeId],
121+
),
122+
).rejects.toMatchObject({ code: "23514" })
116123
await database.query(
117124
`INSERT INTO builds (id, prototype_id, number, state)
118125
VALUES ($1, $2, 1, 'successful')`,

0 commit comments

Comments
 (0)