@@ -15,7 +15,6 @@ use bencher_schema::context::{ApiContext, Database, DbConnection};
1515use bencher_schema:: model:: server:: QueryServer ;
1616use bencher_token:: TokenKey ;
1717use diesel:: { connection:: SimpleConnection , Connection } ;
18- use diesel_migrations:: { embed_migrations, EmbeddedMigrations , MigrationHarness } ;
1918use dropshot:: {
2019 ApiDescription , ConfigDropshot , ConfigLogging , ConfigLoggingIfExists , ConfigLoggingLevel ,
2120 ConfigTls , HttpServer ,
@@ -29,7 +28,6 @@ use super::{plus::Plus, DEFAULT_BUSY_TIMEOUT};
2928use crate :: endpoints:: Api ;
3029
3130const DATABASE_URL : & str = "DATABASE_URL" ;
32- const MIGRATIONS : EmbeddedMigrations = embed_migrations ! ( "../../lib/bencher_schema/migrations" ) ;
3331
3432pub struct ConfigTx {
3533 pub config : Config ,
@@ -40,8 +38,8 @@ pub struct ConfigTx {
4038pub enum ConfigTxError {
4139 #[ error( "Failed to create server logger: {0}" ) ]
4240 CreateLogger ( std:: io:: Error ) ,
43- #[ error( "Failed to run database migrations: {0}" ) ]
44- Migrations ( Box < dyn std :: error :: Error + Send + Sync > ) ,
41+ #[ error( "{0}" ) ]
42+ Migrations ( # [ from ] bencher_schema :: MigrationError ) ,
4543 #[ error( "Failed to run database pragma: {0}" ) ]
4644 Pragma ( diesel:: result:: Error ) ,
4745 #[ error( "Failed to parse role based access control (RBAC) rules: {0}" ) ]
@@ -172,7 +170,7 @@ fn into_context(
172170 }
173171
174172 info ! ( & log, "Running database migrations" ) ;
175- run_migrations ( & mut database_connection) ?;
173+ bencher_schema :: run_migrations ( & mut database_connection) ?;
176174
177175 let data_store = if let Some ( data_store) = json_database. data_store {
178176 Some ( data_store. try_into ( ) . map_err ( ConfigTxError :: DataStore ) ?)
@@ -243,27 +241,6 @@ fn diesel_database_url(log: &Logger, database_path: &str) {
243241 std:: env:: set_var ( DATABASE_URL , database_path) ;
244242}
245243
246- fn run_migrations ( database : & mut DbConnection ) -> Result < ( ) , ConfigTxError > {
247- // It is not possible to enable or disable foreign key constraints in the middle of a multi-statement transaction
248- // (when SQLite is not in autocommit mode).
249- // Attempting to do so does not return an error; it simply has no effect.
250- // https://www.sqlite.org/foreignkeys.html#fk_enable
251- // Therefore, we must run all migrations with foreign key constraints disabled.
252- // Still use `PRAGMA foreign_keys = OFF` in the migration scripts to disable foreign key constraints when using the CLI.
253- database
254- . batch_execute ( "PRAGMA foreign_keys = OFF" )
255- . map_err ( ConfigTxError :: Pragma ) ?;
256- database
257- . run_pending_migrations ( MIGRATIONS )
258- . map ( |_| ( ) )
259- . map_err ( ConfigTxError :: Migrations ) ?;
260- database
261- . batch_execute ( "PRAGMA foreign_keys = ON" )
262- . map_err ( ConfigTxError :: Pragma ) ?;
263-
264- Ok ( ( ) )
265- }
266-
267244#[ cfg( feature = "plus" ) ]
268245fn run_litestream (
269246 database : & mut DbConnection ,
0 commit comments