k98kurz / sqloquent

Python 3+ SQL ORM system inspired by Eloquent
Other
1 stars 0 forks source link

Make `make migration --model ...` compute alter from diff with existing schema #9

Open k98kurz opened 1 month ago

k98kurz commented 1 month ago

Is your feature request related to a problem? Please describe.

The sqloquent make migration --model ... CLI command currently creates a create table migration by parsing the columns attribute of a model and the type annotations. But if the model schema needs to be changed, this will not work because the table already exists. In such cases, the best option is to use a simpler migration generator, e.g. sqloquent make migration --alter ....

Describe the solution you'd like

Update the make migration --model command to attempt to read the current schema from the database for the table, compute the difference between the current schema and the desired schema encoded in the model class, and produce an alter table migration that drops/adds columns as appropriate in both the up and down functions.

Describe alternatives you've considered

Not adding the feature, but I kinda want it.

Additional context

Not a high priority since it is already possible to do this manually.