Skip to content

Renaming a column using the experimental column override should produce a rename column statement #4635

Closed

Description

@marcelomendoncasoares

Problem to Solve

When an existing table model receives the experimental column key to override the name of the column in the database, the migration system produces ADD/REMOVE entries instead of RENAME. This largely defeats the purpose of using the key to rename columns for already existing tables.

Proposal

If the model field still has the same type and received a column override, the migration system should generate a rename statement instead of dropping and re-creating the table.

Use Case

A developer wants to change the field of a model without loosing data on the database. Then they could do:

  1. Override the column name to the new name of the field - while keeping the field name unchanged.
  2. Generate the model.
  3. Create a migration.
  4. Change the name of the field to the new name, removing the column override.
  5. Generate the model.

Since on steps 4-5 the table definition will not change (same columns with same types), no migration will be generated and the model field will be safely renamed with no data loss.

Alternatives

Modify the SQL for the rename manually.

Additional context

Will close #4602.

How experienced are you with this library?

Expert - Experienced and comfortable with using this library in complex projects

Are you interested in working on a PR for this?

  • I want to work on this

Metadata

Metadata

Labels

area: migrationsIssues related to creating or executing migrations.area: modelsIssues related to Serverpod Models.enhancementNew feature or request

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions