mysqlmigratorpostgresql


Namemysqlmigratorpostgresql JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/archenthusiastic/mysqlmigratorpostgresql
SummaryA library to migrate MySQL databases to PostgreSQL with ease and automation.
upload_time2024-12-13 03:53:55
maintainerNone
docs_urlNone
authorarchenthusiastic
requires_python>=3.7
licenseMIT
keywords mysql postgresql database migration python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MysqlMigratorPostgreSQL
```python
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:

```python
# 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:

```python
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()

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/archenthusiastic/mysqlmigratorpostgresql",
    "name": "mysqlmigratorpostgresql",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "mysql, postgresql, database migration, python",
    "author": "archenthusiastic",
    "author_email": "abuawadsantiago@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/40/37/3ab2e3f2ca4d22c358620d8ad1945ec9cc8226b307b55908d139f91767c2/mysqlmigratorpostgresql-0.1.0.tar.gz",
    "platform": null,
    "description": "# MysqlMigratorPostgreSQL\r\n```python\r\npip install mysqlmigratorpostgresql\r\n```\r\n\r\n## Introduction\r\n\r\n**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.\r\n\r\nThe library offers:\r\n- Easy connection to MySQL and PostgreSQL servers.\r\n- Automated table migration, including columns and data types.\r\n- Efficient connection and error handling.\r\n- A modular and extensible design.\r\n\r\n---\r\n\r\n## Reserved Word Dictionary\r\n\r\nDuring 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:\r\n\r\n| **MySQL Type**         | **PostgreSQL Type**   | **Description**                                                                |\r\n|------------------------|------------------------|---------------------------------------------------------------------------------|\r\n| `INT`                 | `INTEGER`             | Fixed-size integers.                                                           |\r\n| `VARCHAR(n)`          | `TEXT`                | PostgreSQL does not require strict text limits.                                |\r\n| `TEXT`                | `TEXT`                | Maintains the same type for long text fields.                                  |\r\n| `FLOAT`               | `REAL`                | Floating-point values.                                                         |\r\n| `DOUBLE`              | `DOUBLE PRECISION`    | Higher precision floating-point values in PostgreSQL.                          |\r\n| `DATE`                | `DATE`                | Standard date in `YYYY-MM-DD` format.                                          |\r\n| `DATETIME`            | `TIMESTAMP`           | Date and time with timezone.                                                   |\r\n| `TINYINT(1)`          | `BOOLEAN`             | Interpreted as a logical value (`TRUE` or `FALSE`).                            |\r\n| `ENUM`                | `TEXT`                | Converted to text since PostgreSQL does not directly support the `ENUM` type.  |\r\n\r\n---\r\n\r\n## Code Details\r\n\r\n### **General Structure**\r\n\r\nThe library follows a modular approach. Each functionality is defined in a specific file:\r\n- **`connect_mysql.py`**: Handles connection to a MySQL server.\r\n- **`connect_postgresql.py`**: Handles connection to a PostgreSQL server.\r\n- **`migrator.py`**: Orchestrates the migration of tables and data.\r\n\r\n---\r\n\r\n### **Changes in Data Types**\r\n\r\nThe logic to convert MySQL data types to PostgreSQL is located in `migrator.py`. Here is the key code fragment with explanation:\r\n\r\n```python\r\n# Data type mapping\r\nif \"int\" in column_type:\r\n    postgres_type = \"INTEGER\"\r\nelif \"varchar\" in column_type or \"text\" in column_type:\r\n    postgres_type = \"TEXT\"\r\nelif \"float\" in column_type or \"double\" in column_type:\r\n    postgres_type = \"REAL\"\r\nelif \"date\" in column_type:\r\n    postgres_type = \"DATE\"\r\nelif \"tinyint(1)\" in column_type:\r\n    postgres_type = \"BOOLEAN\"\r\nelse:\r\n    postgres_type = \"TEXT\"  # Default type if no specific mapping is found\r\n```\r\n\r\n---\r\n\r\n## Example Code\r\n\r\nHere is a functional example demonstrating how to use the library to migrate all tables from a MySQL database to PostgreSQL:\r\n\r\n```python\r\nfrom mysqlmigratorpostgresql import MysqlMigratorPostgreSQL\r\n\r\n# Instantiate the migrator\r\nmigrator = MysqlMigratorPostgreSQL()\r\n\r\n# Connect to MySQL\r\nmigrator.connect_mysql(\r\n    host=\"localhost\",\r\n    port=3306,  # Default MySQL port\r\n    user=\"root\",\r\n    password=\"password\",  # Replace with your password\r\n    database=\"databases_name\"\r\n)\r\n\r\n# Connect to PostgreSQL\r\nmigrator.connect_postgresql(\r\n    host=\"localhost\",\r\n    port=5432,  # Default PostgreSQL port\r\n    user=\"postgres\",\r\n    password=\"password\",  # Replace with your password\r\n    database=\"databases_name\"\r\n)\r\n\r\n# Migrate all tables\r\nmigrator.migrate_all()\r\n\r\n# Close connections\r\nmigrator.close_connections()\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A library to migrate MySQL databases to PostgreSQL with ease and automation.",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://github.com/archenthusiastic/mysqlmigratorpostgresql#readme",
        "Homepage": "https://github.com/archenthusiastic/mysqlmigratorpostgresql",
        "Source": "https://github.com/archenthusiastic/mysqlmigratorpostgresql",
        "Tracker": "https://github.com/archenthusiastic/mysqlmigratorpostgresql/issues"
    },
    "split_keywords": [
        "mysql",
        " postgresql",
        " database migration",
        " python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2472c5d7689c8246877cb69d88fadfb3e72b4bf3c6bd4917bec82e1bcd119d9f",
                "md5": "cc8c329c13525ae67d638bf1b0a4fe37",
                "sha256": "1d659d877d87129dac69289c414718c421d09f85ce0dbbfe515a78a156b1c955"
            },
            "downloads": -1,
            "filename": "mysqlmigratorpostgresql-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cc8c329c13525ae67d638bf1b0a4fe37",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6483,
            "upload_time": "2024-12-13T03:53:53",
            "upload_time_iso_8601": "2024-12-13T03:53:53.938334Z",
            "url": "https://files.pythonhosted.org/packages/24/72/c5d7689c8246877cb69d88fadfb3e72b4bf3c6bd4917bec82e1bcd119d9f/mysqlmigratorpostgresql-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "40373ab2e3f2ca4d22c358620d8ad1945ec9cc8226b307b55908d139f91767c2",
                "md5": "e63b6b328169a705b5c789aea4db5020",
                "sha256": "22d055f8b0e430e591147116207ef0173a6a81938d8d6c6acdbf8a3b8ce491e7"
            },
            "downloads": -1,
            "filename": "mysqlmigratorpostgresql-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e63b6b328169a705b5c789aea4db5020",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5477,
            "upload_time": "2024-12-13T03:53:55",
            "upload_time_iso_8601": "2024-12-13T03:53:55.342282Z",
            "url": "https://files.pythonhosted.org/packages/40/37/3ab2e3f2ca4d22c358620d8ad1945ec9cc8226b307b55908d139f91767c2/mysqlmigratorpostgresql-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-13 03:53:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "archenthusiastic",
    "github_project": "mysqlmigratorpostgresql",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mysqlmigratorpostgresql"
}
        
Elapsed time: 0.40019s