-
-
Notifications
You must be signed in to change notification settings - Fork 557
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
feat: migration support group name #2457
Conversation
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.
thank you. it's such a useful feature, however, I think we need to perform create column if not exists
on startup, otherwise it'd break existing users.
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 @cuipeiyu, thanks for the PR!! Sorry for the delay.
I think we already have this feature build in but it works in a different way. Instead of adding an extra group
field in the existing seaql_migrations
table. We can create multiple seaql_migrations
table in a single database.
By default the migration table is named seaql_migrations
:
use crate::common::migration::*;
use sea_orm_migration::prelude::*;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(m20220118_000001_create_cake_table::Migration),
Box::new(m20220118_000002_create_fruit_table::Migration),
Box::new(m20220118_000003_seed_cake_table::Migration),
Box::new(m20220118_000004_create_tea_enum::Migration),
Box::new(m20220923_000001_seed_cake_table::Migration),
Box::new(m20230109_000001_seed_cake_table::Migration),
]
}
}
We can override the name of the migration table using the migration_table_name
method:
use crate::common::migration::*;
use sea_orm_migration::prelude::*;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(m20220118_000001_create_cake_table::Migration),
Box::new(m20220118_000002_create_fruit_table::Migration),
Box::new(m20220118_000003_seed_cake_table::Migration),
Box::new(m20220118_000004_create_tea_enum::Migration),
Box::new(m20220923_000001_seed_cake_table::Migration),
Box::new(m20230109_000001_seed_cake_table::Migration),
]
}
fn migration_table_name() -> sea_orm::DynIden {
Alias::new("override_migration_table_name").into_iden()
}
}
So, we will have 2 SeaORM migration table in the database and we can execute each set of migration files independently:
// Migration table named `seaql_migrations`
default::Migrator::up(db).await?;
// Migration table named `override_migration_table_name`
override_migration_table_name::Migrator::up(db).await?;
Thanks for your review, glad there is a more elegant way to implement it. I have closed this PR! |
PR Info
New Features
Bug Fixes
Breaking Changes
Changes