From 3e7acc87bb27f8e45ee3556eb488e790a185c6cd Mon Sep 17 00:00:00 2001 From: Xin Hao Date: Wed, 3 Jul 2024 23:20:49 +0800 Subject: [PATCH 1/2] Using embed migration for Postgres --- Cargo.lock | 3 +++ crates/arroyo-api/Cargo.toml | 3 ++- crates/arroyo-api/build.rs | 20 ++++++++++++++++++++ crates/arroyo-controller/Cargo.toml | 1 + crates/arroyo-controller/build.rs | 20 ++++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 0a2d3d287..9c1702c33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -493,6 +493,7 @@ dependencies = [ "rand 0.8.5", "rand_chacha 0.3.1", "refinery", + "refinery-core", "regress 0.6.0", "reqwest", "rusqlite", @@ -636,6 +637,7 @@ dependencies = [ "quote", "rand 0.8.5", "refinery", + "refinery-core", "regex", "reqwest", "rusqlite", @@ -7196,6 +7198,7 @@ dependencies = [ "async-trait", "cfg-if", "log", + "postgres", "regex", "rusqlite", "serde", diff --git a/crates/arroyo-api/Cargo.toml b/crates/arroyo-api/Cargo.toml index 68ba7523b..b573793c1 100644 --- a/crates/arroyo-api/Cargo.toml +++ b/crates/arroyo-api/Cargo.toml @@ -97,4 +97,5 @@ postgres = "0.19.5" arroyo-types = { path = "../arroyo-types" } utoipa = "3" rusqlite = "0.31.0" -refinery = { version = "0.8.14", features = ["rusqlite"] } \ No newline at end of file +refinery = { version = "0.8.14", features = ["rusqlite"] } +refinery-core = { version = "0.8.14", features = ["postgres"] } diff --git a/crates/arroyo-api/build.rs b/crates/arroyo-api/build.rs index 3080991ba..e17329ac9 100644 --- a/crates/arroyo-api/build.rs +++ b/crates/arroyo-api/build.rs @@ -1,5 +1,11 @@ use cornucopia::{CodegenSettings, Error}; use postgres::{Client, NoTls}; +use refinery_core::postgres::Client as MigrationClient; + +mod embedded { + use refinery::embed_migrations; + embed_migrations!("./migrations"); +} fn main() -> Result<(), Error> { let queries_path = "queries"; @@ -26,6 +32,20 @@ fn main() -> Result<(), Error> { panic!("Could not connect to postgres: arroyo:arroyo@localhost:5432/arroyo") }); + let mut migration_client = MigrationClient::configure() + .dbname("arroyo") + .host("localhost") + .port(5432) + .user("arroyo") + .password("arroyo") + .connect(NoTls) + .unwrap_or_else(|_| { + panic!("Could not connect to postgres: arroyo:arroyo@localhost:5432/arroyo") + }); + embedded::migrations::runner() + .run(&mut migration_client) + .unwrap(); + let mut sqlite = rusqlite::Connection::open_in_memory().expect("Couldn't open sqlite memory connection"); let migrations = refinery::load_sql_migrations("sqlite_migrations").unwrap(); diff --git a/crates/arroyo-controller/Cargo.toml b/crates/arroyo-controller/Cargo.toml index 16e2a1df3..15daa5b83 100644 --- a/crates/arroyo-controller/Cargo.toml +++ b/crates/arroyo-controller/Cargo.toml @@ -72,3 +72,4 @@ postgres = "0.19.5" arroyo-types = { path = "../arroyo-types" } rusqlite = "0.31.0" refinery = { version = "0.8.14", features = ["rusqlite"] } +refinery-core = { version = "0.8.14", features = ["postgres"] } diff --git a/crates/arroyo-controller/build.rs b/crates/arroyo-controller/build.rs index 704d9a22b..fd05ac573 100644 --- a/crates/arroyo-controller/build.rs +++ b/crates/arroyo-controller/build.rs @@ -1,5 +1,11 @@ use cornucopia::{CodegenSettings, Error}; use postgres::{Client, NoTls}; +use refinery_core::postgres::Client as MigrationClient; + +mod embedded { + use refinery::embed_migrations; + embed_migrations!("../arroyo-api/migrations"); +} fn main() -> Result<(), Error> { let queries_path = "queries"; @@ -26,6 +32,20 @@ fn main() -> Result<(), Error> { panic!("Could not connect to postgres: arroyo:arroyo@localhost:5432/arroyo") }); + let mut migration_client = MigrationClient::configure() + .dbname("arroyo") + .host("localhost") + .port(5432) + .user("arroyo") + .password("arroyo") + .connect(NoTls) + .unwrap_or_else(|_| { + panic!("Could not connect to postgres: arroyo:arroyo@localhost:5432/arroyo") + }); + embedded::migrations::runner() + .run(&mut migration_client) + .unwrap(); + let mut sqlite = rusqlite::Connection::open_in_memory().expect("Couldn't open sqlite memory connection"); let migrations = refinery::load_sql_migrations("../arroyo-api/sqlite_migrations").unwrap(); From 5434a57733e393893e9cbf2d8bb58d14fb7cc4ab Mon Sep 17 00:00:00 2001 From: Xin Hao Date: Wed, 3 Jul 2024 23:25:17 +0800 Subject: [PATCH 2/2] cargo fmt --- crates/arroyo-controller/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/arroyo-controller/build.rs b/crates/arroyo-controller/build.rs index fd05ac573..5b5ac8164 100644 --- a/crates/arroyo-controller/build.rs +++ b/crates/arroyo-controller/build.rs @@ -32,7 +32,7 @@ fn main() -> Result<(), Error> { panic!("Could not connect to postgres: arroyo:arroyo@localhost:5432/arroyo") }); - let mut migration_client = MigrationClient::configure() + let mut migration_client = MigrationClient::configure() .dbname("arroyo") .host("localhost") .port(5432)