Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated sql migrations #43

Open
MustCodeAl opened this issue Jun 6, 2022 · 2 comments
Open

Automated sql migrations #43

MustCodeAl opened this issue Jun 6, 2022 · 2 comments

Comments

@MustCodeAl
Copy link

MustCodeAl commented Jun 6, 2022

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

@Wulf
Copy link
Owner

Wulf commented Jun 10, 2022

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

@Wulf
Copy link
Owner

Wulf commented Oct 1, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants