File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,19 +14,16 @@ private static async Task LoadDatabase(this WebApplication application)
1414 {
1515 application . Logger . Log ( LogLevel . Information , "Loading database..." ) ;
1616
17- await using ( var scope = application . Services . CreateAsyncScope ( ) )
17+ await using var scope = application . Services . CreateAsyncScope ( ) ;
18+ var dataContext = scope . ServiceProvider . GetService < DataContext > ( ) ;
19+ var migrations = await dataContext . Database . GetPendingMigrationsAsync ( ) ;
20+ application . Logger . Log ( LogLevel . Information , "Database initialized." ) ;
21+ if ( migrations . ToArray ( ) . Length > 0 )
1822 {
19- var dataContext = scope . ServiceProvider . GetService < DataContext > ( ) ;
20- var migrations = await dataContext . Database . GetPendingMigrationsAsync ( ) ;
21- if ( dataContext == null ) throw new Exception ( "No Database Context found..." ) ;
22- application . Logger . Log ( LogLevel . Information , "Database initialized." ) ;
23- if ( migrations . ToArray ( ) . Length > 0 )
24- {
25- await dataContext . Database . MigrateAsync ( ) ;
26- application . Logger . Log ( LogLevel . Information , "Database migrated." ) ;
27- }
28-
29- application . Logger . Log ( LogLevel . Information , "Database ready to accept connections." ) ;
23+ await dataContext . Database . MigrateAsync ( ) ;
24+ application . Logger . Log ( LogLevel . Information , "Database migrated." ) ;
3025 }
26+
27+ application . Logger . Log ( LogLevel . Information , "Database ready to accept connections." ) ;
3128 }
3229}
You can’t perform that action at this time.
0 commit comments