Skip to content

Connection used by migrations loaded from elsewhere #749

Answered by billy1624
fabioluciano asked this question in Q&A
Discussion options

You must be logged in to vote

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.

// establish connection to database and apply migrations
// -> create post table if not exists
let conn = sea_orm::Database::connect(&db_url).await.unwrap();
Migrator::up(&conn, None).await.unwrap();

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by billy1624
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #744 on May 19, 2022 02:41.