Skipping Constraint Renames in Schema Migrations
How do I instruct Atlas to not generate RENAME
commands for table constraints in schema migrations when running commands
such as migrate diff
, schema apply
, schema plan
, etc.?
Answer
Atlas supports loading database schema definitions from HCL, SQL, and ORM-based sources. When using ORMs like GORM or Django, which don't support naming all database constraints explicitly, the database often generates names automatically when creating them. This can lead to inconsistencies between the unnamed constraints defined in the schema and those that exist in the actual database.
As part of the migration planning process, Atlas loads the desired schema into a dev-database, and since the dev-database
may generate different constraint names than the live database, Atlas might emit RENAME
statements in schema migration
plans to reconcile these differences.
These rename operations are unnecessary and clutter migration history, as they're not meaningful and often result from
random naming. Therefore, to skip comparing constraint names and avoid generating RENAME
commands, use the diff.skip
block in your atlas.hcl
configuration:
env "local" {
diff {
skip {
rename_constraint = true
}
}
}
For more details on the diff.skip
configuration and its available attributes, please refer to our documentation.