import { useState } from "react"; import { getSchemas, getTables, startMigration, getProgress } from "../api"; export default function PostgreSQLPostgreSQLMigrator() { const [srcHost, setSrcHost] = useState(""); const [srcUser, setSrcUser] = useState(""); const [srcPass, setSrcPass] = useState(""); const [schemas, setSchemas] = useState([]); const [selectedSchemas, setSelectedSchemas] = useState([]); const [destHost, setDestHost] = useState(""); const [destUser, setDestUser] = useState(""); const [destPass, setDestPass] = useState(""); const [progress, setProgress] = useState({ percent: 0, message: "Waiting to start..." }); const [loading, setLoading] = useState(false); const loadSchemas = async () => { setLoading(true); try { const data = await getSchemas("psql_psql", { host: srcHost, user: srcUser, pass: srcPass }); setSchemas(data.schemas || []); if (data.error) { alert("Error loading schemas: " + data.error); } } catch { setSchemas([]); } finally { setLoading(false); } }; const handleMigration = async () => { const payload = { DB_HOST: srcHost, DB_USER: srcUser, DB_PASS: srcPass, DB_NAME: selectedSchemas[0] || "", DEST_HOST: destHost, DEST_USER: destUser, DEST_PASS: destPass, DEST_NAME: selectedSchemas[0] || "", ONLY_SCHEMAS: selectedSchemas.join(",") }; try { const data = await startMigration("psql_psql", payload); if (data.success) { pollProgress(); } else { alert("Migration failed: " + (data.error || "Unknown error")); } } catch (error) { console.error("Error starting migration:", error); alert("Connection error: " + error.message); } }; const pollProgress = async () => { try { const data = await getProgress("psql_psql"); setProgress(data); if (data.status === "error") { alert("Migration error: " + (data.message || "Unknown error")); } else if (data.percent < 100 && data.status !== "completed") { setTimeout(pollProgress, 2000); } } catch (error) { console.error("Error polling progress:", error); setTimeout(pollProgress, 2000); } }; return (
Migrate PostgreSQL schemas and tables.
{JSON.stringify(progress, null, 2)}