Replies: 5 comments 2 replies
-
|
Hey @gd87429, hi again! I think the atomic migration is database specific? For example, in MySQL, the DDL statement such as I'd love to support atomic migrations but seems it's not a easy task. As we need to come up with a plan for each of our supported database, unless I miss something. What's your suggestions on that? |
Beta Was this translation helpful? Give feedback.
-
|
The general recommendation is that you call https://docs.rs/sea-orm-migration/latest/sea_orm_migration/manager/struct.SchemaManager.html#method.get_connection and then open a transaction on it |
Beta Was this translation helpful? Give feedback.
-
|
What is doable but require more effort is for I imagine: pub enum SchemaManager<'c> {
DatabaseConnection(&'c DatabaseConnection),
DatabaseTransaction(DatabaseTransaction),
}
// and thus
impl SchemaManager {
fn get_transaction(&self) -> Self {
if postgres {
match self {
DatabaseConnection(conn) => Self::DatabaseTransaction(conn.begin()),
DatabaseTransaction(tran) => Self::DatabaseTransaction(tran.begin()), // this will open a nested transaction
}
} else {
self.clone()
}
}
}Just an imagination, I have not tested whether it will pass all the lifetime requirements. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
I think maybe we can try another way to just make sure the migration will be executed successfully. Like dryrun the migraiton, it will not update the database actually just check if the migration itself is ok. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If you run
Migrator::up()in parallel (like when you spin up multiple servers), is there a chance the same migration might run more than once?If yes -- are there plans to build-in support for atomic migrations, or should the user make sure migration cannot be applied twice (like checking if data exists before seeding the table)?
Beta Was this translation helpful? Give feedback.
All reactions