refinery icon indicating copy to clipboard operation
refinery copied to clipboard

Support Rust migrations from refinery_cli

Open Raytwo opened this issue 4 years ago • 4 comments

Greetings,

As the title say, I'd like to suggest supporting Rust migrations as an enhancement for refinery_cli.

I'm actually not sure if I'm the one doing something wrong, but after a quick glance at the code and my attempt being met with migration V1__Initial is missing from the filesystem when trying to run the command on a directory that works perfectly fine when migrating from code, I'd assume it just isn't supported at the moment.

Thanks for your great work, as someone with no experience with databases, refinery has been a lifesaver.

Raytwo avatar Sep 29 '21 12:09 Raytwo

Hi, and thanks for the interest! Yeah Rust Migrations are currently not supported by refinery_cli we would need to parse and compile the rust code in the migrations at runtime and I thought it's just easier if one creates a binary crate, adds refinery and includes the Rust migrations. Can you elaborate on your use case? Thanks :)

jxs avatar Sep 30 '21 09:09 jxs

Oh well, that's actually a good solution too, I didn't even stop to consider it.

My use case for the moment is simply creating tables in a freshly made PostgreSQL database running in Docker, with Rust migrations being ran by Rocket as a Adhoc Ignite function.

I just felt like having to run my software to initialize the tables wasn't good practice and was considering using refinery_cli instead, which would also be better considering the person working with me on the frontend is not a Rust user and it seemed to me that letting them run the migrations through a command line was a better approach than asking them to build and run the backend.

Also, considering we generate models for the project using sea-orm-cli with a database-first approach, this also suggests that not having to run the backend to generate the database when the models aren't even present in the code would be preferable.

I'm eventually considering running refinery through build.rs for the time being, which while not the best, would probably be better than having to run the software for it.

I'll keep your suggestion in mind though! Thanks for the fast reply.

Raytwo avatar Sep 30 '21 18:09 Raytwo

I just felt like having to run my software to initialize the tables wasn't good practice

why not? it runs once and if it's already migrated refinery won't run the migrations again

jxs avatar Sep 30 '21 21:09 jxs

Because currently the process is: Set up database > run my API > migrations get applied > close software > generate models with sea-orm-cli > start writing code

It’s not such a big deal, really, but I think your approach with having a separate project to be able to run the migrations is cleaner

Raytwo avatar Oct 01 '21 06:10 Raytwo