22//!
33//! ```sh
44//! export DATABASE_URL=postgres://localhost/your_db
5- //! diesel migration run
65//! cargo run -p example-diesel-async-postgres
76//! ```
87//!
@@ -22,11 +21,14 @@ use axum::{
2221use diesel:: prelude:: * ;
2322use diesel_async:: {
2423 pooled_connection:: { bb8, AsyncDieselConnectionManager } ,
25- AsyncPgConnection , RunQueryDsl ,
24+ AsyncMigrationHarness , AsyncPgConnection , RunQueryDsl ,
2625} ;
26+ use diesel_migrations:: { embed_migrations, EmbeddedMigrations , MigrationHarness } ;
2727use std:: net:: SocketAddr ;
2828use tracing_subscriber:: { layer:: SubscriberExt , util:: SubscriberInitExt } ;
2929
30+ pub const MIGRATIONS : EmbeddedMigrations = embed_migrations ! ( ) ;
31+
3032// normally part of your generated schema.rs file
3133table ! {
3234 users ( id) {
@@ -68,6 +70,9 @@ async fn main() {
6870 let config = AsyncDieselConnectionManager :: < diesel_async:: AsyncPgConnection > :: new ( db_url) ;
6971 let pool = bb8:: Pool :: builder ( ) . build ( config) . await . unwrap ( ) ;
7072
73+ let mut harness = AsyncMigrationHarness :: new ( pool. get_owned ( ) . await . unwrap ( ) ) ;
74+ harness. run_pending_migrations ( MIGRATIONS ) . unwrap ( ) ;
75+
7176 // build our application with some routes
7277 let app = Router :: new ( )
7378 . route ( "/user/list" , get ( list_users) )
0 commit comments