feat: create database migrations utility bin

This commit is contained in:
Aravinth Manivannan 2024-05-04 22:40:32 +05:30
parent 6500f4c122
commit 6df89a8558
Signed by: realaravinth
GPG Key ID: F8F50389936984FF
4 changed files with 1772 additions and 0 deletions

1
utils/db-migrations/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

1737
utils/db-migrations/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View 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"] }

View 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();
}