2023-06-03 06:27:00 +02:00
|
|
|
use serde::Deserialize;
|
|
|
|
use std::env;
|
|
|
|
use std::fs;
|
2023-06-05 17:59:45 +02:00
|
|
|
use urlencoding::encode;
|
2023-06-03 06:27:00 +02:00
|
|
|
|
2023-06-01 00:12:59 +02:00
|
|
|
use sea_orm_migration::prelude::*;
|
|
|
|
|
2023-06-03 06:27:00 +02:00
|
|
|
#[cfg(feature = "convert")]
|
2023-06-01 18:32:15 +02:00
|
|
|
mod vec_to_json;
|
|
|
|
|
2023-06-05 17:59:45 +02:00
|
|
|
#[tokio::main]
|
2023-06-01 00:12:59 +02:00
|
|
|
async fn main() {
|
2023-06-03 06:27:00 +02:00
|
|
|
let cwd = env::current_dir().unwrap();
|
|
|
|
let yml = fs::File::open(cwd.join("../../.config/default.yml"))
|
2023-06-05 17:59:45 +02:00
|
|
|
.expect("Failed to open '.config/default.yml'");
|
|
|
|
let config: Config = serde_yaml::from_reader(yml).expect("Failed to parse yaml");
|
2023-06-03 06:27:00 +02:00
|
|
|
|
|
|
|
env::set_var(
|
|
|
|
"DATABASE_URL",
|
|
|
|
format!(
|
|
|
|
"postgres://{}:{}@{}:{}/{}",
|
2023-06-05 17:59:45 +02:00
|
|
|
config.db.user,
|
|
|
|
encode(&config.db.pass),
|
|
|
|
config.db.host,
|
|
|
|
config.db.port,
|
|
|
|
config.db.db,
|
2023-06-03 06:27:00 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2023-06-01 00:12:59 +02:00
|
|
|
cli::run_cli(migration::Migrator).await;
|
2023-06-01 18:32:15 +02:00
|
|
|
|
|
|
|
#[cfg(feature = "convert")]
|
|
|
|
vec_to_json::convert().await;
|
2023-06-01 00:12:59 +02:00
|
|
|
}
|
2023-06-03 06:27:00 +02: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,
|
|
|
|
}
|