File tree 2 files changed +7
-21
lines changed 2 files changed +7
-21
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ use std::backtrace::Backtrace;
17
17
use std:: panic;
18
18
19
19
use anyhow:: Context ;
20
- use sqlx:: { Connection , MySqlConnection } ;
21
20
use tracing:: Instrument ;
22
21
23
22
mod logging;
@@ -32,29 +31,10 @@ async fn main() -> anyhow::Result<()> {
32
31
33
32
let _guard = logging:: init ( ) . context ( "initialize logging" ) ?;
34
33
let runtime_span = tracing:: info_span!( "runtime::startup" ) ;
35
-
36
34
let api_config = runtime_span
37
35
. in_scope ( cs2kz_api:: Config :: new)
38
36
. context ( "load config" ) ?;
39
37
40
- let mut connection = MySqlConnection :: connect ( api_config. database_url . as_str ( ) )
41
- . instrument ( runtime_span. clone ( ) )
42
- . await
43
- . context ( "connect to database" ) ?;
44
-
45
- // Run database migrations.
46
- //
47
- // If this fails, e.g. because the migration files have changed since they last have been
48
- // applied, the API will fail to startup, so the migrations can be fixed.
49
- sqlx:: migrate!( "./database/migrations" )
50
- . run ( & mut connection)
51
- . instrument ( runtime_span. clone ( ) )
52
- . await
53
- . context ( "run migrations" ) ?;
54
-
55
- // Don't wanna keep around a dead connection!
56
- drop ( connection) ;
57
-
58
38
let old_panic_hook = panic:: take_hook ( ) ;
59
39
60
40
// If anything anywhere ever panics, we want to log it.
Original file line number Diff line number Diff line change 9
9
use std:: convert:: Infallible ;
10
10
use std:: sync:: Arc ;
11
11
12
+ use anyhow:: Context ;
12
13
use axum:: async_trait;
13
14
use axum:: extract:: FromRequestParts ;
14
15
use axum:: http:: request;
@@ -61,7 +62,7 @@ impl State {
61
62
} ;
62
63
63
64
/// Creates a new [`State`].
64
- pub async fn new ( api_config : crate :: Config ) -> Result < Self > {
65
+ pub async fn new ( api_config : crate :: Config ) -> anyhow :: Result < Self > {
65
66
tracing:: debug!( ?api_config, "initializing application state" ) ;
66
67
tracing:: debug! {
67
68
url = %api_config. database_url,
@@ -77,6 +78,11 @@ impl State {
77
78
. connect ( config. database_url . as_str ( ) )
78
79
. await ?;
79
80
81
+ sqlx:: migrate!( "./database/migrations" )
82
+ . run ( & database)
83
+ . await
84
+ . context ( "run migrations" ) ?;
85
+
80
86
let http_client = reqwest:: Client :: new ( ) ;
81
87
let jwt_state = JwtState :: new ( & config) . map ( Arc :: new) ?;
82
88
You can’t perform that action at this time.
0 commit comments