init_mysql_to_postgres

Function init_mysql_to_postgres 

Source
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:

  1. Validates MySQL connection string
  2. Connects to MySQL and verifies connection
  3. Extracts database name from connection string
  4. Lists all tables from MySQL database
  5. 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?;