diff --git a/nautilus_core/cli/src/database/postgres.rs b/nautilus_core/cli/src/database/postgres.rs index 07f43d390b9b..3b5acf03f0b0 100644 --- a/nautilus_core/cli/src/database/postgres.rs +++ b/nautilus_core/cli/src/database/postgres.rs @@ -37,6 +37,7 @@ pub async fn run_database_command(opt: DatabaseOpt) -> anyhow::Result<()> { &pg, pg_connect_options.database, pg_connect_options.password, + config.schema, ) .await? } diff --git a/nautilus_core/cli/src/opt.rs b/nautilus_core/cli/src/opt.rs index 8ef5b9c2b1d2..1df35a0e78f2 100644 --- a/nautilus_core/cli/src/opt.rs +++ b/nautilus_core/cli/src/opt.rs @@ -51,6 +51,9 @@ pub struct DatabaseConfig { /// Password for connecting to the database #[arg(long)] pub password: Option, + /// Directory path to the schema files + #[arg(long)] + pub schema: Option, } #[derive(Parser, Debug, Clone)] diff --git a/nautilus_core/infrastructure/src/sql/pg.rs b/nautilus_core/infrastructure/src/sql/pg.rs index ad9c504e7be4..fd31fea4c917 100644 --- a/nautilus_core/infrastructure/src/sql/pg.rs +++ b/nautilus_core/infrastructure/src/sql/pg.rs @@ -130,7 +130,12 @@ fn get_schema_dir() -> anyhow::Result { }) } -pub async fn init_postgres(pg: &PgPool, database: String, password: String) -> anyhow::Result<()> { +pub async fn init_postgres( + pg: &PgPool, + database: String, + password: String, + schema_dir: Option, +) -> anyhow::Result<()> { info!("Initializing Postgres database with target permissions and schema"); // create public schema match sqlx::query("CREATE SCHEMA IF NOT EXISTS public;") @@ -155,7 +160,7 @@ pub async fn init_postgres(pg: &PgPool, database: String, password: String) -> a } } // execute all the sql files in schema dir - let schema_dir = get_schema_dir()?; + let schema_dir = schema_dir.unwrap_or_else(|| get_schema_dir().unwrap()); let mut sql_files = std::fs::read_dir(schema_dir)?.collect::, std::io::Error>>()?; for file in &mut sql_files {