Summary
Model.sync({ alter: true }) compares a formatted model generated-column expression with a formatted expression returned by schema introspection.
Databases can normalize generated-column expressions by adding parentheses, casts, identifier quoting, or whitespace. These formatting-only differences can make equivalent expressions compare as different.
Required changes
Update generated-column drift detection to avoid treating formatting-only expression differences as a schema mismatch.
Use the established SQL-expression formatting API for BaseSqlExpression values where appropriate. Normalize equivalent dialect-specific expression formatting before comparison, or classify an unverified text difference as requiring a migration without reporting it as a definite mismatch.
Preserve the current safety behavior for dialects that cannot inspect generated columns. Preserve the SQLite changeColumn path for actual generated-column changes.
Rationale
A semantically unchanged generated column can currently make sync({ alter: true }) fail on dialects that return generated expressions through introspection. SQLite can also rebuild the table repeatedly for an unchanged expression.
Affected area
packages/core/src/model.js
- Generated-column expression formatting and schema introspection utilities
Acceptance criteria
- Equivalent generated-column expressions with dialect formatting differences do not cause false drift detection.
- Actual expression or generated-column mode changes remain detected.
- Dialects without generated-column introspection retain the existing migration-required safety behavior.
- SQLite does not rebuild a table solely for formatting-only expression differences.
- Tests cover normalized database expressions such as added parentheses, casts, quoting, or whitespace.
Backlinks
Summary
Model.sync({ alter: true })compares a formatted model generated-column expression with a formatted expression returned by schema introspection.Databases can normalize generated-column expressions by adding parentheses, casts, identifier quoting, or whitespace. These formatting-only differences can make equivalent expressions compare as different.
Required changes
Update generated-column drift detection to avoid treating formatting-only expression differences as a schema mismatch.
Use the established SQL-expression formatting API for
BaseSqlExpressionvalues where appropriate. Normalize equivalent dialect-specific expression formatting before comparison, or classify an unverified text difference as requiring a migration without reporting it as a definite mismatch.Preserve the current safety behavior for dialects that cannot inspect generated columns. Preserve the SQLite
changeColumnpath for actual generated-column changes.Rationale
A semantically unchanged generated column can currently make
sync({ alter: true })fail on dialects that return generated expressions through introspection. SQLite can also rebuild the table repeatedly for an unchanged expression.Affected area
packages/core/src/model.jsAcceptance criteria
Backlinks