Clone any database to a local Docker PostgreSQL container with schema and/or data transfer via pg_dump. Supports three modes: schema only, full clone, and sample data. Includes container lifecycle management (start/stop/remove) in the Admin panel, progress tracking with collapsible process log, and automatic connection creation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ConnectionConfig {
|
|
pub id: String,
|
|
pub name: String,
|
|
pub host: String,
|
|
pub port: u16,
|
|
pub user: String,
|
|
pub password: String,
|
|
pub database: String,
|
|
pub ssl_mode: Option<String>,
|
|
pub color: Option<String>,
|
|
pub environment: Option<String>,
|
|
}
|
|
|
|
impl ConnectionConfig {
|
|
pub fn connection_url(&self) -> String {
|
|
self.connection_url_for_db(&self.database)
|
|
}
|
|
|
|
pub fn connection_url_for_db(&self, database: &str) -> String {
|
|
let ssl = self.ssl_mode.as_deref().unwrap_or("prefer");
|
|
format!(
|
|
"postgres://{}:{}@{}:{}/{}?sslmode={}",
|
|
urlencoded(&self.user),
|
|
urlencoded(&self.password),
|
|
self.host,
|
|
self.port,
|
|
urlencoded(database),
|
|
ssl
|
|
)
|
|
}
|
|
}
|
|
|
|
fn urlencoded(s: &str) -> String {
|
|
s.chars()
|
|
.map(|c| match c {
|
|
':' | '/' | '?' | '#' | '[' | ']' | '@' | '!' | '$' | '&' | '\'' | '(' | ')'
|
|
| '*' | '+' | ',' | ';' | '=' | '%' | ' ' => {
|
|
format!("%{:02X}", c as u8)
|
|
}
|
|
_ => c.to_string(),
|
|
})
|
|
.collect()
|
|
}
|