Repository navigation
Make Device.id the primary key - #94
Merged
Merged
Conversation
Device had only unique indexes, so logical replication (a database move with live migration) rejects every UPDATE and DELETE on it. The migration reuses the existing unique index on id as the primary key: no table rewrite and no scan, since the column is already NOT NULL. Code that runs on the old Prisma client works with the migrated table.
adamshiervani
added a commit
that referenced
this pull request
Nov 6, 2026
- #94: Device.id becomes the primary key, so a live database move (logical replication) can replicate updates and deletes on Device. The migration was applied to the production database before this merge.
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.
Devicehad only unique indexes. Logical replication, as used by a live database move, rejects every UPDATE and DELETE on a table without a replica identity.Device_id_keyindex intoDevice_pkey(PRIMARY KEY USING INDEX): no rebuild, no scan.Checked on PostgreSQL 14: existing rows kept, no drift against
schema.prisma, replicated UPDATE/DELETE work, duplicate ids still rejected. Unit (110) and e2e (87) pass with the old and the new Prisma client.Note
Medium Risk
Schema migration on a core table: production deploy order and DB state matter, though the migration is designed to be low-impact (index reuse, no scan).
Overview
Promotes
Device.idto the table primary key so PostgreSQL has a replica identity for logical replication (UPDATE/DELETE no longer rejected).A new migration reuses the existing unique index (
Device_id_key) withPRIMARY KEY USING INDEX, avoiding a rebuild or full table scan.schema.prismareplaces@uniqueonidwith@idso the client matches the database.No application code changes in this PR; deploy can run the migration before shipping the updated Prisma schema.
Reviewed by Cursor Bugbot for commit 4347f19. Bugbot is set up for automated code reviews on this repo. Configure here.