Automated sql migrations
MustCodeAl opened this issue · comments
https://github.com/tvallotton/models
this tool will generate migrations for structs as long as they are annotated with a derive model macro and macros to describe the constraints on the sql fields.
this are the migrations generated by diesel
this is the migration generated by the models_cli tool with the models generate -r
command
hey @AlNotAlbert thanks again for creating this issue -- I'd love to have something like this in create-rust-app. I've been thinking about how we should include this, and the best way is probably by adding it as an option when create-rust-app
is invoked in a generated project.
The flow would look something like this:
# 1. create a project
create-rust-app migration-generation-test
cd migration-generation test
# 2. create your stricts marked with `#[derive(Model)]`, etc.
# 3. run create-rust-app and select generate-migrations
create-rust-app
> Generate migrations
# ... the option should run the models-cli migration generator and then rename the folders appropriately.
Implementation-wise, we would need to:
- add an option to generate migrations (or other commands) here
- add appropriate handling here
- check that the models-cli exists (if not, instruct the user on how to install it)
- run the specific models-cli command
- restructuring the output of models-cli to match deisel
This is preferable for now until we start supporting sqlx or other diesel alternatives since we don't include any extra dependencies and expect the user to install the models-cli
Thanks for your patience, it's been busy~
Please do ask any questions you have or if you think there's a better way of doing this, I'd love to hear it
Diesel CLI now includes support for generating migrations based on the difference of your schema.rs file and your local database.
Check out: http://diesel.rs/news/2_1_0_release.html
It's slightly different than tvallotton's models
tool