@@ -32,6 +32,7 @@ use diesel::r2d2::{ConnectionManager, Pool};
32
32
use juniper:: graphiql:: graphiql_source;
33
33
use juniper:: http:: GraphQLRequest ;
34
34
use serde:: { Deserialize , Serialize } ;
35
+ use std:: path:: PathBuf ;
35
36
use std:: sync:: Arc ;
36
37
use structopt:: StructOpt ;
37
38
use wundergraph:: scalar:: WundergraphScalarValue ;
@@ -75,6 +76,24 @@ fn graphql(
75
76
. body ( serde_json:: to_string ( & res) ?) )
76
77
}
77
78
79
+ fn run_migrations ( conn : & DBConnection ) {
80
+ let mut migration_path = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
81
+ migration_path. push ( "migrations" ) ;
82
+ if cfg ! ( feature = "postgres" ) {
83
+ migration_path. push ( "pg" ) ;
84
+ } else if cfg ! ( feature = "sqlite" ) {
85
+ migration_path. push ( "sqlite" ) ;
86
+ }
87
+ let pending_migrations =
88
+ :: diesel_migrations:: mark_migrations_in_directory ( conn, & migration_path)
89
+ . unwrap ( )
90
+ . into_iter ( )
91
+ . filter_map ( |( migration, run) | if run { None } else { Some ( migration) } ) ;
92
+
93
+ :: diesel_migrations:: run_migrations ( conn, pending_migrations, & mut :: std:: io:: stdout ( ) )
94
+ . expect ( "Failed to run migrations" ) ;
95
+ }
96
+
78
97
#[ allow( clippy:: print_stdout) ]
79
98
fn main ( ) {
80
99
let opt = Opt :: from_args ( ) ;
@@ -85,8 +104,8 @@ fn main() {
85
104
. max_size ( 1 )
86
105
. build ( manager)
87
106
. expect ( "Failed to init pool" ) ;
88
- // ::diesel_migrations::run_pending_migrations(&pool.get().expect("Failed to get db connection"))
89
- // . expect("Failed to run migrations" );
107
+
108
+ run_migrations ( & pool . get ( ) . expect ( "Failed to get db connection" ) ) ;
90
109
91
110
let query = Query :: < MyContext < DBConnection > > :: default ( ) ;
92
111
let mutation = Mutation :: < MyContext < DBConnection > > :: default ( ) ;
0 commit comments