Skip to content

Commit

Permalink
Using embed migration for Postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxins committed Jul 18, 2024
1 parent 5dd0372 commit 3e7acc8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/arroyo-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
refinery = { version = "0.8.14", features = ["rusqlite"] }
refinery-core = { version = "0.8.14", features = ["postgres"] }
20 changes: 20 additions & 0 deletions crates/arroyo-api/build.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions crates/arroyo-controller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
20 changes: 20 additions & 0 deletions crates/arroyo-controller/build.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand Down

0 comments on commit 3e7acc8

Please sign in to comment.