Wulf / create-rust-app

Set up a modern rust+react web app by running one command.

Home Page:https://create-rust-app.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.
b9cd5595bd3a6127411d9e24db67bde3

this are the migrations generated by diesel
e0c0391772f9649b7eca37941e0f42cc

this is the migration generated by the models_cli tool with the models generate -r command
2e34a5bd1965901d07b6979752b3ea7d

commented

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:

  1. add an option to generate migrations (or other commands) here
  2. 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