Support "rename field" in automatic migration generator

Open
#209 2 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@Soroushsrd is already working on this.

Since Apr 15, 2025.

Assessment

This issue has not been assessed yet.

Description

enhancement

We should support renaming fields in the automatic migration generator.

This is more complicated than most of the other operations. This is because we can't reliably detect renaming fields (we only see that a field has been removed and then created). For starters, we could detect if a field was renamed by keeping all of its properties intact. Then, we could add some heuristics (like for instance, we see that a field was removed but then recreated with most of its original properties). This, however, needs to be interactive—we need to ask the developer if they actually renamed the field (and then create either a rename, or delete+create operations depending on their reply).

The entry point is probably somewhere in the make_alter_model_operations function: https://github.com/cot-rs/cot/blob/2bbb09699bf7b74c41bb323338a02c528de1acff/cot-cli/src/migration_generator.rs#L329

This will require adding a new OperationInner variant: https://github.com/cot-rs/cot/blob/2bbb09699bf7b74c41bb323338a02c528de1acff/cot/src/db/migrations.rs#L460

Note that the "rename field" operation will need to store the old name of the field, so that an implementation of Operation::backwards can be created.

Dominant language
Rust
Stars
1.1k
Forks
57
Avg merge
17h 39m
Merged PRs (30d)
12

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cot-rs/cot

All issues in cot-rs/cot

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.