Merge pull request '[PR]: Fix database connection URL' (#10263) from nmkj/calckey:fix-database-url into develop

Reviewed-on: https://codeberg.org/calckey/calckey/pulls/10263
This commit is contained in:
Kainoa Kanter 2023-06-05 21:36:48 +00:00
commit c32d26e6c7
3 changed files with 13 additions and 6 deletions

View File

@ -13,7 +13,6 @@ default = []
convert = ["dep:native-utils"]
[dependencies]
async-std = { version = "1", features = ["attributes", "tokio1"] }
serde_json = "1.0.96"
native-utils = { path = "../", optional = true }
indicatif = { version = "0.17.4", features = ["tokio"] }
@ -21,6 +20,7 @@ tokio = { version = "1.28.2", features = ["full"] }
futures = "0.3.28"
serde_yaml = "0.9.21"
serde = { version = "1.0.163", features = ["derive"] }
urlencoding = "2.1.2"
[dependencies.sea-orm-migration]
version = "0.11.0"

View File

@ -1,24 +1,29 @@
use serde::Deserialize;
use std::env;
use std::fs;
use urlencoding::encode;
use sea_orm_migration::prelude::*;
#[cfg(feature = "convert")]
mod vec_to_json;
#[async_std::main]
#[tokio::main]
async fn main() {
let cwd = env::current_dir().unwrap();
let yml = fs::File::open(cwd.join("../../.config/default.yml"))
.expect("Unable to read '.config/default.yml'");
let config: Config = serde_yaml::from_reader(yml).expect("Unable to parse");
.expect("Failed to open '.config/default.yml'");
let config: Config = serde_yaml::from_reader(yml).expect("Failed to parse yaml");
env::set_var(
"DATABASE_URL",
format!(
"postgres://{}:{}@{}:{}/{}",
config.db.user, config.db.pass, config.db.host, config.db.port, config.db.db
config.db.user,
encode(&config.db.pass),
config.db.host,
config.db.port,
config.db.db,
),
);

View File

@ -222,7 +222,9 @@ export const db = new DataSource({
export async function initDb(force = false) {
await nativeInitDatabase(
`postgres://${config.db.user}:${config.db.pass}@${config.db.host}:${config.db.port}/${config.db.db}`,
`postgres://${config.db.user}:${encodeURIComponent(config.db.pass)}@${
config.db.host
}:${config.db.port}/${config.db.db}`,
);
if (force) {
if (db.isInitialized) {