diff --git a/packages/backend/native-utils/migration/Cargo.toml b/packages/backend/native-utils/migration/Cargo.toml index 3813eccd80..4dee156ef3 100644 --- a/packages/backend/native-utils/migration/Cargo.toml +++ b/packages/backend/native-utils/migration/Cargo.toml @@ -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" diff --git a/packages/backend/native-utils/migration/src/main.rs b/packages/backend/native-utils/migration/src/main.rs index a845a41ff4..f0f761f657 100644 --- a/packages/backend/native-utils/migration/src/main.rs +++ b/packages/backend/native-utils/migration/src/main.rs @@ -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, ), ); diff --git a/packages/backend/src/db/postgre.ts b/packages/backend/src/db/postgre.ts index 9ffaf596c8..0fa5fdff67 100644 --- a/packages/backend/src/db/postgre.ts +++ b/packages/backend/src/db/postgre.ts @@ -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) {