sea-orm
sea-orm copied to clipboard
Enable migration generation in modules
Adds
Generating a new migration no works even if migrations are not at the root of their own crate.
I didn't want to have an entire separate crate just for migrations. So I put them into a module in my regular crate. sea-orm-cli migrate generate accepts a flag --migration-dir, which seemed perfect for my use case. However, that flag still assumes there is a directory src/ and that the migrator definition is in lib.rs.
If there is a directory src/ and a file lib.rs, this PR doesn't change anything, so I don't think it's a breaking change. If src/ doesn't exist, it will look in the parent directory instead. If there is no lib.rs, it will look for a mod.rs instead.
For reference, this is what my file structure looks like:
my-app/
├─ src/
│ ├─ db/
│ │ ├─ migration/
│ │ │ ├─ mod.rs/
│ │ │ ├─ m20220101_000001_create_table.rs/
│ │ ├─ migration_cli.rs
│ │ ├─ mod.rs
│ ├─ main.rs
├─ Cargo.toml
Both db/mod.rs and db/migration_cli.rs contain mod migration;. That way, both binaries (main.rs, the main app, and migration_cli.rs, a thin wrapper around the migration cli api) can access my migrations.
I'm looking forward to discussions and suggestions!