feat: create database migrations utility bin
This commit is contained in:
parent
6500f4c122
commit
6df89a8558
1
utils/db-migrations/.gitignore
vendored
Normal file
1
utils/db-migrations/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
1737
utils/db-migrations/Cargo.lock
generated
Normal file
1737
utils/db-migrations/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
10
utils/db-migrations/Cargo.toml
Normal file
10
utils/db-migrations/Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "db-migrations"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "2.9.0"
|
||||
sqlx = { version = "0.7.4", features = ["runtime-tokio-rustls", "postgres", "time"] }
|
24
utils/db-migrations/src/main.rs
Normal file
24
utils/db-migrations/src/main.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use std::env;
|
||||
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
#[actix_rt::main]
|
||||
async fn main() {
|
||||
//TODO featuregate sqlite and postgres
|
||||
postgres_migrate().await;
|
||||
}
|
||||
|
||||
async fn postgres_migrate() {
|
||||
let db_url = env::var("DATABASE_URL").expect("set DATABASE_URL env var");
|
||||
let db = PgPoolOptions::new()
|
||||
.max_connections(2)
|
||||
.connect(&db_url)
|
||||
.await
|
||||
.expect("Unable to form database pool");
|
||||
|
||||
sqlx::migrate!("../../migrations/")
|
||||
.run(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
Loading…
Reference in a new issue