pub async fn init_mysql_to_postgres(
mysql_url: &str,
target_url: &str,
) -> Result<()>Expand description
Initial replication from MySQL to PostgreSQL
Performs one-time replication of MySQL database to PostgreSQL target using JSONB storage:
- Validates MySQL connection string
- Connects to MySQL and verifies connection
- Extracts database name from connection string
- Lists all tables from MySQL database
- For each table:
- Converts rows to JSONB format
- Creates JSONB table in PostgreSQL
- Batch inserts all data
All MySQL data is stored as JSONB with metadata:
- id: Primary key or auto-generated ID
- data: Complete row as JSON object
- _source_type: “mysql”
- _migrated_at: Timestamp of replication
§Arguments
mysql_url- MySQL connection string (mysql://…)target_url- PostgreSQL connection string for target (Seren) database
§Returns
Returns Ok(()) if replication completes successfully.
§Errors
This function will return an error if:
- MySQL connection string is invalid
- Cannot connect to MySQL database
- Database name is not specified in connection string
- Cannot connect to target PostgreSQL database
- Table conversion fails
- Database creation or insert operations fail
§Examples
init_mysql_to_postgres(
"mysql://user:pass@localhost:3306/mydb",
"postgresql://user:pass@seren.example.com/targetdb"
).await?;