-
-
Notifications
You must be signed in to change notification settings - Fork 551
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
Use file!
in migration files
#705
Comments
I did some testing and found out So I'm not sure it worth the effort to change for template, the string already generated by cli. |
I imagine we can use a compile time const fn to split out the file name. |
This is doable. I guess we can introduce a derive for pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
std::path::Path::new(file!())
.file_stem()
.map(|f| f.to_str().unwrap())
.unwrap()
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
...
} |
I usually do the following: In all migration files, include:
I defined the macro like this: #[macro_export]
macro_rules! migration_file {
() => {
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
std::path::Path::new(file!())
.file_name()
.unwrap()
.to_str()
.unwrap()
.split(".")
.next()
.unwrap()
}
}
};
} |
Thanks. This is quite neat! |
sea-orm/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs
Lines 6 to 10 in cdc70f4
Can we use https://doc.rust-lang.org/std/macro.file.html instead of manually copying the name?
We'd probably want to change the migration template too
The text was updated successfully, but these errors were encountered: