-
-
Notifications
You must be signed in to change notification settings - Fork 539
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
Enable migration generation in modules #933
Conversation
Previously, migration generation expected migrations to be at the crate root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @remlse, welcome! And thanks for the great contributions!
I think we should document the updated behaviour on the get_full_migration_dir
and get_migrator_filepath
method because the logic is getter more complex it's not easy to understand at a glance.
Which directory/file be checked for existence then what's the fallback?
Thoughts? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @remlse, just notice a problem. Before updating the migrator file mod.rs
/lib.rs
. A backup file will be created with file extension of .bak
.
sea-orm/sea-orm-cli/src/commands/migrate.rs
Lines 143 to 144 in 1a2090f
// create a backup of the migrator file in case something goes wrong let migrator_backup_filepath = migrator_filepath.with_file_name("lib.rs.bak");
However, now that migrator can be either reside in mod.rs
/lib.rs
. We should change the line to:
let migrator_backup_filepath = migrator_filepath.with_extension("rs.bak");
@billy1624 thanks for having a look! I think I'll get around to it on the weekend, I'll add some documentation and fix the backup filename. |
@billy1624 I've added some documentation. Some internally and some to be displayed by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! @remlse The documentation looks great :)
Thank you for the contribution. Too bad for the delay, I am surprised this patch still applies |
* Enable migration generation in modules Previously, migration generation expected migrations to be at the crate root. * Fix migration backup file extension * Document behavior of migration_dir
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 directorysrc/
and that the migrator definition is inlib.rs
.If there is a directory
src/
and a filelib.rs
, this PR doesn't change anything, so I don't think it's a breaking change. Ifsrc/
doesn't exist, it will look in the parent directory instead. If there is nolib.rs
, it will look for amod.rs
instead.For reference, this is what my file structure looks like:
Both
db/mod.rs
anddb/migration_cli.rs
containmod migration;
. That way, both binaries (main.rs
, the main app, andmigration_cli.rs
, a thin wrapper around the migration cli api) can access my migrations.I'm looking forward to discussions and suggestions!