rorm-orm / rorm-cli

CLI tool of rorm
MIT License
1 stars 0 forks source link

"Alter" field doesn't alter enum #5

Open gammelalf opened 11 months ago

gammelalf commented 11 months ago

On postgres: When adding a new enum variant, the drop column doesn't delete the enum type, so the new creation is ignored

WebFreak001 commented 9 months ago

the issue, at least on postgres, is actually that there is never any new type creation being done.

On CreateField the pre_statements field is set to None, making it not try to CREATE TYPE, at least in postgres.

Only on CreateModel the pre_statements are generated and evaluated.

so there are two things to fix here:

1) CreateField is broken with enums (choice), because it never creates the type (also making it not error here for you, since there is no attempt to re-create an existing type) 2) there should be a proper AlterField or more fine grained alternatives such as AddChoice/RemoveChoice - also so that choice fields are not deleted and recreated in production

As well as arguably DeleteField with choice should probably delete the enum type that was created beforehand.

to work around this while keeping migration-generating capabilities, it would also be nice to be able to create raw SQL statements that set structure_safe, but still have some kind of internal CreateField/DeleteField steps so that the rorm-cli internal model would understand what is being done. (tracking issue: #6)