Run migration at application startup
How to apply all pending migration at application startup?
You can run the migration programmatically at startup by providing the database connection to the Migrator::up
method.
#![allow(unused)] fn main() { // Initialize database connection let db = Database::connect(&db_url).await?; // Run all pending migrations Migrator::up(&conn, None).await?; }
Checkout the examples below: