Skip to content

feat!: use string primary keys and normalise Entity/File schema#17

Open
johnf wants to merge 2 commits intofeat/schema-migration-basefrom
feat/schema-migration-string-pks
Open

feat!: use string primary keys and normalise Entity/File schema#17
johnf wants to merge 2 commits intofeat/schema-migration-basefrom
feat/schema-migration-string-pks

Conversation

@johnf
Copy link
Copy Markdown
Collaborator

@johnf johnf commented Mar 27, 2026

Summary

  • BREAKING: Entity and File primary keys change from auto-increment integers to string-based IDs
  • Entity.rocrateId renamed to Entity.id, File.fileId renamed to File.id
  • File now has entityId FK to Entity (instead of Entity having fileId)
  • Redundant fields removed from File (memberOf, rootCollection, contentLicenseId)
  • findFirst replaced with findUnique for primary key lookups
  • Promise.all for parallel count+findMany queries
  • Simplified transformer types (removed discriminated unions)
  • Includes two migration files for staged rollout

Depends on: #11, #12, #13, #14, #15, #16 (all merged into this branch)

Test plan

  • pnpm lint passes
  • pnpm test passes
  • pnpm generate succeeds with new schema
  • Migrations apply cleanly to existing database
  • All routes return correct data with new field names

@github-actions
Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 100% (🎯 100%) 318 / 318
🔵 Statements 100% (🎯 100%) 330 / 330
🔵 Functions 100% (🎯 100%) 52 / 52
🔵 Branches 100% (🎯 100%) 149 / 149
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/app.ts 100% 100% 100% 100%
src/routes/crate.ts 100% 100% 100% 100%
src/routes/entities.ts 100% 100% 100% 100%
src/routes/entity.ts 100% 100% 100% 100%
src/routes/file.ts 100% 100% 100% 100%
src/routes/files.ts 100% 100% 100% 100%
src/routes/search.ts 100% 100% 100% 100%
src/transformers/default.ts 100% 100% 100% 100%
src/utils/errors.ts 100% 100% 100% 100%
src/utils/headers.ts 100% 100% 100% 100%
src/utils/queryBuilder.ts 100% 100% 100% 100%
Generated in workflow #51 for commit 7d74aac by the Vitest Coverage Report Action

@johnf johnf changed the base branch from main to feat/schema-migration-base March 27, 2026 05:06
johnf added 2 commits March 27, 2026 16:12
BREAKING CHANGE: Entity and File primary keys change from auto-increment
integers to string-based IDs. Entity.rocrateId is renamed to Entity.id,
File.fileId is renamed to File.id. File now has an entityId foreign key
to Entity instead of Entity having a fileId. Redundant fields removed
from File (memberOf, rootCollection, contentLicenseId).

Also includes:
- findFirst replaced with findUnique for primary key lookups
- Promise.all for parallel count+findMany queries
- Simplified transformer types (removed discriminated unions)
@johnf johnf force-pushed the feat/schema-migration-base branch from 1a94134 to c3301c3 Compare March 27, 2026 05:13
@johnf johnf force-pushed the feat/schema-migration-string-pks branch from 7d74aac to 17cae47 Compare March 27, 2026 05:13
model File {
id Int @id @default(autoincrement())
id String @id @db.VarChar(768)
entityId String @db.VarChar(768)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can also remove the entityId altogether because the id is already unique and corresponds one-to-one with the id of the Entity table.

updatedAt DateTime @updatedAt

meta Json?
entity Entity @relation(fields: [entityId], references: [id])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
entity Entity @relation(fields: [entityId], references: [id])
entity Entity @relation(fields: [id], references: [id])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Example if we get rid of the entityId

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants