Ensure schema-migration consistency

When modifying database schemas, ensure complete alignment between schema definitions and SQL migration scripts. Every field, column, constraint, or relationship defined in your schema must have a corresponding migration operation.

copy reviewer prompt

Prompt

Reviewer Prompt

When modifying database schemas, ensure complete alignment between schema definitions and SQL migration scripts. Every field, column, constraint, or relationship defined in your schema must have a corresponding migration operation.

Common issues to avoid:

  • Adding fields to schema models without corresponding ADD COLUMN statements in migrations
  • Changing field attributes without updating migration constraints
  • Forgetting to add columns before defining foreign keys that reference them

Example of problematic changes:

// Schema changes:
model EmailAccount {
-  id           String   @id @default(cuid())
+  email        String   @id
   writingStyle String?
+  userId       String
+  accountId    String   @unique
}

Without matching migration statements:

-- Missing corresponding SQL operations:
-- ADD COLUMN "writingStyle" TEXT
-- ADD COLUMN "userId" TEXT NOT NULL
-- ADD COLUMN "accountId" TEXT NOT NULL UNIQUE

Failing to maintain this consistency will cause migration failures at runtime. Always verify that every schema field change has a matching migration operation before submitting your PR.

Source discussions