feat(models): add support for generated and identity columns
* extend Column struct with Generated, GenerationExpression, Identity, and IdentityGeneration fields * update queryColumns to handle new column properties * modify migration writer to avoid altering generated and identity columns * add tests to ensure correct handling of generated and identity columns
This commit is contained in:
@@ -433,6 +433,16 @@ func (w *MigrationWriter) generateAlterTableScripts(schema *models.Schema, model
|
||||
Body: sql,
|
||||
}
|
||||
scripts = append(scripts, script)
|
||||
} else if currentCol.Generated || currentCol.Identity {
|
||||
// GENERATED ALWAYS ... STORED columns and GENERATED ... AS IDENTITY
|
||||
// columns are both driven by Postgres-side machinery (an expression, or
|
||||
// a backing sequence + attidentity flag) that DBML cannot express, so
|
||||
// the model side always looks like drift (missing type modifiers, no
|
||||
// default, NOT NULL mismatches, etc). None of their properties are
|
||||
// alterable the normal way (e.g. dropping a generated column's default
|
||||
// requires DROP EXPRESSION, not DROP DEFAULT; identity columns have no
|
||||
// default to alter at all), so these DB-side-only columns are left
|
||||
// untouched rather than diffed.
|
||||
} else if !columnsEqual(modelCol, currentCol) {
|
||||
// Column exists but properties changed
|
||||
if !columnTypesEqual(modelCol, currentCol) {
|
||||
|
||||
Reference in New Issue
Block a user