feat: add Clone Database to Docker functionality
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>
This commit is contained in:
@@ -16,6 +16,10 @@ pub struct ConnectionConfig {
|
||||
|
||||
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={}",
|
||||
@@ -23,7 +27,7 @@ impl ConnectionConfig {
|
||||
urlencoded(&self.password),
|
||||
self.host,
|
||||
self.port,
|
||||
urlencoded(&self.database),
|
||||
urlencoded(database),
|
||||
ssl
|
||||
)
|
||||
}
|
||||
|
||||
57
src-tauri/src/models/docker.rs
Normal file
57
src-tauri/src/models/docker.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DockerStatus {
|
||||
pub installed: bool,
|
||||
pub daemon_running: bool,
|
||||
pub version: Option<String>,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CloneMode {
|
||||
SchemaOnly,
|
||||
FullClone,
|
||||
SampleData,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct CloneToDockerParams {
|
||||
pub source_connection_id: String,
|
||||
pub source_database: String,
|
||||
pub container_name: String,
|
||||
pub pg_version: String,
|
||||
pub host_port: Option<u16>,
|
||||
pub clone_mode: CloneMode,
|
||||
pub sample_rows: Option<u32>,
|
||||
pub postgres_password: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct CloneProgress {
|
||||
pub clone_id: String,
|
||||
pub stage: String,
|
||||
pub percent: u8,
|
||||
pub message: String,
|
||||
pub detail: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TuskContainer {
|
||||
pub container_id: String,
|
||||
pub name: String,
|
||||
pub status: String,
|
||||
pub host_port: u16,
|
||||
pub pg_version: String,
|
||||
pub source_database: Option<String>,
|
||||
pub source_connection: Option<String>,
|
||||
pub created_at: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct CloneResult {
|
||||
pub container: TuskContainer,
|
||||
pub connection_id: String,
|
||||
pub connection_url: String,
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod ai;
|
||||
pub mod connection;
|
||||
pub mod docker;
|
||||
pub mod history;
|
||||
pub mod lookup;
|
||||
pub mod management;
|
||||
|
||||
Reference in New Issue
Block a user