Connection used by migrations loaded from elsewhere #749
-
MotivationI'm using SeaORM to create the databases to a CLI app. In the current implementation, the sea-orm/sea-orm-migration/src/cli.rs Lines 11 to 20 in e005626 And, if i need to migrate the database, using, for example, a configuration file, other then .env, i cant. Proposed SolutionsChange the method signature to accept a connection, instead of load from dotenv directly. Something like pub async fn run_cli<M>(migrator: M, connection: DatabaseConnection)
where
M: MigratorTrait,
{
let app = build_cli();
get_matches(migrator, &connection, app).await;
} |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
I tried to implement the solution in a new pull request, but i dont know how to implement the connection in actix and in the other frameworks in the test scenarios. |
Beta Was this translation helpful? Give feedback.
-
Hey @fabioluciano, thanks for the suggestion and contribution! If you want to run migration on startup, you can refer to our Actix examples. Basically, you can initialize the connection then pass it into methods in sea-orm/examples/actix_example/src/main.rs Lines 173 to 176 in 3f90c09 |
Beta Was this translation helpful? Give feedback.
-
Ow.... Let me try this 👯 |
Beta Was this translation helpful? Give feedback.
-
Ow! Worked! Thank you very much @billy1624 |
Beta Was this translation helpful? Give feedback.
-
Welcome! :D |
Beta Was this translation helpful? Give feedback.
Hey @fabioluciano, thanks for the suggestion and contribution! If you want to run migration on startup, you can refer to our Actix examples. Basically, you can initialize the connection then pass it into methods in
MigratorTrait
to run the migrations. So actually you don't need the migration CLI.sea-orm/examples/actix_example/src/main.rs
Lines 173 to 176 in 3f90c09