Electron100 / butane

An ORM for Rust with a focus on simplicity and on writing Rust, not SQL
Apache License 2.0
83 stars 11 forks source link

Add migrate & unmigrate core helpers #250

Closed jayvdb closed 2 months ago

jayvdb commented 2 months ago

These helpers could be placed on Migrations or on BackendConnection, but it feels sensible to keep them separate and use these helpers to join them. Keen to reconsider that.

My reason for keeping them simple is anyone invoking these helpers can also play with the connection and migrations in advance, either to detect any problems in advance, or after, and editing the migrations to control the start / end of the migrate/rollback operations.

I'm also not keen on trying to use these helpers in butane_cli, as it would require moving a lot of CLI-ish feedback into an Err, but I am happy to do that - probably by creating a new Error enum for this.

Electron100 commented 2 months ago

Thanks for adding this, I too had been noticing it would be useful. I think I would vote for placing these methods on Migrations because of the parallelism with apply on Migration. You can apply a single Migration, or migrate a whole Migrations collection. It's also slightly more ergonomic to use with

migrations.migrate(&mut connection)

vs

migrations::migrate(&mut connection, &migrations)

I could also see naming the method apply_all or apply_unapplied, but very much don't feel strongly.