Skip to main content

A library to migrate MySQL databases to PostgreSQL with ease and automation.

Project description

MysqlMigratorPostgreSQL

pip install mysqlmigratorpostgresql

Introduction

MysqlMigratorPostgreSQL is a Python library designed to simplify the migration of entire databases from MySQL to PostgreSQL. This tool is ideal for software engineers seeking an automated solution to transfer data and table structures between these two relational database management systems.

The library offers:

  • Easy connection to MySQL and PostgreSQL servers.
  • Automated table migration, including columns and data types.
  • Efficient connection and error handling.
  • A modular and extensible design.

Reserved Word Dictionary

During migration, certain data types in MySQL do not have an exact equivalent in PostgreSQL. Below is a summary of the conversions performed by the library:

MySQL Type PostgreSQL Type Description
INT INTEGER Fixed-size integers.
VARCHAR(n) TEXT PostgreSQL does not require strict text limits.
TEXT TEXT Maintains the same type for long text fields.
FLOAT REAL Floating-point values.
DOUBLE DOUBLE PRECISION Higher precision floating-point values in PostgreSQL.
DATE DATE Standard date in YYYY-MM-DD format.
DATETIME TIMESTAMP Date and time with timezone.
TINYINT(1) BOOLEAN Interpreted as a logical value (TRUE or FALSE).
ENUM TEXT Converted to text since PostgreSQL does not directly support the ENUM type.

Code Details

General Structure

The library follows a modular approach. Each functionality is defined in a specific file:

  • connect_mysql.py: Handles connection to a MySQL server.
  • connect_postgresql.py: Handles connection to a PostgreSQL server.
  • migrator.py: Orchestrates the migration of tables and data.

Changes in Data Types

The logic to convert MySQL data types to PostgreSQL is located in migrator.py. Here is the key code fragment with explanation:

# Data type mapping
if "int" in column_type:
    postgres_type = "INTEGER"
elif "varchar" in column_type or "text" in column_type:
    postgres_type = "TEXT"
elif "float" in column_type or "double" in column_type:
    postgres_type = "REAL"
elif "date" in column_type:
    postgres_type = "DATE"
elif "tinyint(1)" in column_type:
    postgres_type = "BOOLEAN"
else:
    postgres_type = "TEXT"  # Default type if no specific mapping is found

Example Code

Here is a functional example demonstrating how to use the library to migrate all tables from a MySQL database to PostgreSQL:

from mysqlmigratorpostgresql import MysqlMigratorPostgreSQL

# Instantiate the migrator
migrator = MysqlMigratorPostgreSQL()

# Connect to MySQL
migrator.connect_mysql(
    host="localhost",
    port=3306,  # Default MySQL port
    user="root",
    password="password",  # Replace with your password
    database="databases_name"
)

# Connect to PostgreSQL
migrator.connect_postgresql(
    host="localhost",
    port=5432,  # Default PostgreSQL port
    user="postgres",
    password="password",  # Replace with your password
    database="databases_name"
)

# Migrate all tables
migrator.migrate_all()

# Close connections
migrator.close_connections()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mysqlmigratorpostgresql-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mysqlmigratorpostgresql-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file mysqlmigratorpostgresql-0.1.0.tar.gz.

File metadata

  • Download URL: mysqlmigratorpostgresql-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for mysqlmigratorpostgresql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 22d055f8b0e430e591147116207ef0173a6a81938d8d6c6acdbf8a3b8ce491e7
MD5 e63b6b328169a705b5c789aea4db5020
BLAKE2b-256 40373ab2e3f2ca4d22c358620d8ad1945ec9cc8226b307b55908d139f91767c2

See more details on using hashes here.

File details

Details for the file mysqlmigratorpostgresql-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mysqlmigratorpostgresql-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d659d877d87129dac69289c414718c421d09f85ce0dbbfe515a78a156b1c955
MD5 cc8c329c13525ae67d638bf1b0a4fe37
BLAKE2b-256 2472c5d7689c8246877cb69d88fadfb3e72b4bf3c6bd4917bec82e1bcd119d9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page