calckey/packages/backend/native-utils/migration/src/main.rs

51 lines
1.1 KiB
Rust
Raw Normal View History

2023-06-03 04:27:00 +00:00
use serde::Deserialize;
use std::env;
use std::fs;
use urlencoding::encode;
2023-06-03 04:27:00 +00:00
2023-05-31 22:12:59 +00:00
use sea_orm_migration::prelude::*;
2023-06-03 04:27:00 +00:00
#[cfg(feature = "convert")]
2023-06-01 16:32:15 +00:00
mod vec_to_json;
#[tokio::main]
2023-05-31 22:12:59 +00:00
async fn main() {
2023-06-03 04:27:00 +00:00
let cwd = env::current_dir().unwrap();
let yml = fs::File::open(cwd.join("../../.config/default.yml"))
.expect("Failed to open '.config/default.yml'");
let config: Config = serde_yaml::from_reader(yml).expect("Failed to parse yaml");
2023-06-03 04:27:00 +00:00
env::set_var(
"DATABASE_URL",
format!(
"postgres://{}:{}@{}:{}/{}",
config.db.user,
encode(&config.db.pass),
config.db.host,
config.db.port,
config.db.db,
2023-06-03 04:27:00 +00:00
),
);
2023-05-31 22:12:59 +00:00
cli::run_cli(migration::Migrator).await;
2023-06-01 16:32:15 +00:00
#[cfg(feature = "convert")]
vec_to_json::convert().await;
2023-05-31 22:12:59 +00:00
}
2023-06-03 04:27:00 +00:00
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename = "camelCase")]
pub struct Config {
pub db: DbConfig,
}
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename = "camelCase")]
pub struct DbConfig {
pub host: String,
pub port: u32,
pub db: String,
pub user: String,
pub pass: String,
}