@@ -13,7 +13,7 @@ use nyxd_scraper_shared::storage::helpers::log_db_operation_time;
1313use nyxd_scraper_shared:: storage:: { NyxdScraperStorage , NyxdScraperStorageError } ;
1414use sqlx:: types:: time:: { OffsetDateTime , PrimitiveDateTime } ;
1515use tokio:: time:: Instant ;
16- use tracing:: { debug, error, info, instrument, warn } ;
16+ use tracing:: { debug, error, info, instrument} ;
1717
1818#[ derive( Clone ) ]
1919pub struct PostgresScraperStorage {
@@ -22,7 +22,10 @@ pub struct PostgresScraperStorage {
2222
2323impl PostgresScraperStorage {
2424 #[ instrument]
25- pub async fn init ( connection_string : & str ) -> Result < Self , PostgresScraperError > {
25+ pub async fn init (
26+ connection_string : & str ,
27+ run_migrations : & bool ,
28+ ) -> Result < Self , PostgresScraperError > {
2629 debug ! ( "initialising scraper database with '{connection_string}'" , ) ;
2730
2831 let connection_pool = match sqlx:: PgPool :: connect ( connection_string) . await {
@@ -33,12 +36,13 @@ impl PostgresScraperStorage {
3336 }
3437 } ;
3538
36- if let Err ( err) = sqlx:: migrate!( "./sql_migrations" )
37- . run ( & connection_pool)
38- . await
39- {
40- warn ! ( "Failed to initialize SQLx database: {err}" ) ;
41- // return Err(err.into());
39+ if * run_migrations {
40+ if let Err ( err) = sqlx:: migrate!( "./sql_migrations" )
41+ . run ( & connection_pool)
42+ . await
43+ {
44+ return Err ( err. into ( ) ) ;
45+ }
4246 }
4347
4448 info ! ( "Database migration finished!" ) ;
@@ -192,8 +196,11 @@ impl PostgresScraperStorage {
192196impl NyxdScraperStorage for PostgresScraperStorage {
193197 type StorageTransaction = PostgresStorageTransaction ;
194198
195- async fn initialise ( storage : & str ) -> Result < Self , NyxdScraperStorageError > {
196- PostgresScraperStorage :: init ( storage)
199+ async fn initialise (
200+ storage : & str ,
201+ run_migrations : & bool ,
202+ ) -> Result < Self , NyxdScraperStorageError > {
203+ PostgresScraperStorage :: init ( storage, run_migrations)
197204 . await
198205 . map_err ( NyxdScraperStorageError :: from)
199206 }
0 commit comments