Skip to content

Normalize generated-column expressions during sync({ alter: true }) drift detection #18320

Description

@coderabbitai

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

Activity

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

Metadata

Metadata

Assignees

Labels

pending-approvalBug reports that have not been verified yet, or feature requests that have not been accepted yet

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions