@@ -2,11 +2,6 @@ mod rpc_server;
22mod state_indexer;
33mod tx_indexer;
44
5- static META_DB_MIGRATOR : sqlx:: migrate:: Migrator =
6- sqlx:: migrate!( "src/postgres/migrations/meta_db" ) ;
7- static SHARD_DB_MIGRATOR : sqlx:: migrate:: Migrator =
8- sqlx:: migrate!( "src/postgres/migrations/shard_db" ) ;
9-
105#[ derive( borsh:: BorshSerialize , borsh:: BorshDeserialize , Clone , Debug ) ]
116struct PageState {
127 pub last_data_key : Option < String > ,
@@ -45,31 +40,23 @@ pub struct PostgresDBManager {
4540impl PostgresDBManager {
4641 async fn create_meta_db_pool (
4742 database_url : & str ,
48- read_only : bool ,
4943 max_connections : u32 ,
5044 ) -> anyhow:: Result < sqlx:: Pool < sqlx:: Postgres > > {
5145 let pool = sqlx:: postgres:: PgPoolOptions :: new ( )
5246 . max_connections ( max_connections)
5347 . connect ( database_url)
5448 . await ?;
55- if !read_only {
56- Self :: run_migrations ( & META_DB_MIGRATOR , & pool) . await ?;
57- }
5849 Ok ( pool)
5950 }
6051
6152 async fn create_shard_db_pool (
6253 database_url : & str ,
63- read_only : bool ,
6454 max_connections : u32 ,
6555 ) -> anyhow:: Result < sqlx:: Pool < sqlx:: Postgres > > {
6656 let pool = sqlx:: postgres:: PgPoolOptions :: new ( )
6757 . max_connections ( max_connections)
6858 . connect ( database_url)
6959 . await ?;
70- if !read_only {
71- Self :: run_migrations ( & SHARD_DB_MIGRATOR , & pool) . await ?;
72- }
7360 Ok ( pool)
7461 }
7562
@@ -99,25 +86,13 @@ impl PostgresDBManager {
9986 ) ) ?,
10087 } )
10188 }
102-
103- async fn run_migrations (
104- migrator : & sqlx:: migrate:: Migrator ,
105- pool : & sqlx:: Pool < sqlx:: Postgres > ,
106- ) -> anyhow:: Result < ( ) > {
107- migrator. run ( pool) . await ?;
108- Ok ( ( ) )
109- }
11089}
11190
11291#[ async_trait:: async_trait]
11392impl crate :: BaseDbManager for PostgresDBManager {
11493 async fn new ( config : & configuration:: DatabaseConfig ) -> anyhow:: Result < Box < Self > > {
115- let meta_db_pool = Self :: create_meta_db_pool (
116- & config. database_url ,
117- config. read_only ,
118- config. max_connections ,
119- )
120- . await ?;
94+ let meta_db_pool =
95+ Self :: create_meta_db_pool ( & config. database_url , config. max_connections ) . await ?;
12196 let mut shards_pool = std:: collections:: HashMap :: new ( ) ;
12297 let shard_layout = config
12398 . shard_layout
@@ -128,9 +103,7 @@ impl crate::BaseDbManager for PostgresDBManager {
128103 . shards_config
129104 . get ( & shard_id)
130105 . unwrap_or_else ( || panic ! ( "Shard_{shard_id} - database config not found" ) ) ;
131- let pool =
132- Self :: create_shard_db_pool ( database_url, config. read_only , config. max_connections )
133- . await ?;
106+ let pool = Self :: create_shard_db_pool ( database_url, config. max_connections ) . await ?;
134107 shards_pool. insert ( shard_id, pool) ;
135108 }
136109 Ok ( Box :: new ( Self {
0 commit comments