mysqlmigratorpostgree


Namemysqlmigratorpostgree JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/archenthusiastic/mysql-migrator-postgreesql
SummaryLibreria pensada para migrar datos a postgresql de manera versatil auto modulando simplificado el codigo
upload_time2024-12-06 03:45:05
maintainerNone
docs_urlNone
authorarchenthusiastic
requires_python>=3.7
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MysqlMigratorPostgree

## Introducción

```
pip install mysqlmigratorpostgreesql
```
**MysqlMigratorPostgree** es una librería en Python diseñada para facilitar la migración de bases de datos completas desde **MySQL** hacia **PostgreSQL**. Esta herramienta es ideal para ingenieros de software que buscan una solución automatizada para transferir datos y estructuras de tablas entre estos dos sistemas de gestión de bases de datos relacionales.

La librería ofrece:
- Conexión sencilla a servidores de MySQL y PostgreSQL.
- Migración automatizada de tablas, incluyendo columnas y tipos de datos.
- Manejo eficiente de conexiones y errores.
- Un diseño modular y extensible.

---

## Diccionario de Palabras Reservadas

Durante la migración, ciertos tipos de datos en **MySQL** no tienen un equivalente exacto en **PostgreSQL**. Este es un resumen de las conversiones realizadas por la librería:

| **Tipo en MySQL**     | **Tipo en PostgreSQL** | **Descripción**                                                                 |
|------------------------|------------------------|---------------------------------------------------------------------------------|
| `INT`                 | `INTEGER`             | Enteros de tamaño fijo.                                                        |
| `VARCHAR(n)`          | `TEXT`                | PostgreSQL no requiere límites estrictos para textos.                          |
| `TEXT`                | `TEXT`                | Se mantiene el mismo tipo para textos largos.                                  |
| `FLOAT`               | `REAL`                | Valores de punto flotante.                                                     |
| `DOUBLE`              | `DOUBLE PRECISION`    | Valores de mayor precisión en PostgreSQL.                                      |
| `DATE`                | `DATE`                | Fecha estándar en formato `YYYY-MM-DD`.                                        |
| `DATETIME`            | `TIMESTAMP`           | Fecha y hora con zona horaria.                                                 |
| `TINYINT(1)`          | `BOOLEAN`             | Interpretado como un valor lógico (`TRUE` o `FALSE`).                          |
| `ENUM`                | `TEXT`                | Convertido a texto, ya que PostgreSQL no soporta directamente el tipo `ENUM`.  |

---

## Detalles del Código

### **Estructura General**

La librería sigue un enfoque modular. Cada funcionalidad está definida en un archivo específico:
- **`connect_mysql.py`**: Maneja la conexión a un servidor MySQL.
- **`connect_postgresql.py`**: Maneja la conexión a un servidor PostgreSQL.
- **`migrator.py`**: Orquesta la migración de tablas y datos.

---

### **Cambios en los Tipos de Datos**

La lógica para convertir tipos de datos de MySQL a PostgreSQL se encuentra en el archivo `migrator.py`. Aquí está el fragmento clave del código con explicación:

```python
# Mapeo de tipos de datos
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"  # Tipo predeterminado si no hay un mapeo específico
```

## Código de Ejemplo

Aquí tienes un ejemplo funcional que muestra cómo usar la librería para migrar todas las tablas de una base de datos MySQL a PostgreSQL:

```python
from mysqlmigratorpostgree import MysqlMigratorPostgree

# Instanciar el migrador
migrator = MysqlMigratorPostgree()

# Conectar a MySQL
migrator.connect_mysql(
    host="localhost",
    port=3306,  # Puerto predeterminado de MySQL
    user="root",
    password="password",  # Cambiar por tu contraseña
    database="databases_name"
)

# Conectar a PostgreSQL
migrator.connect_postgresql(
    host="localhost",
    port=5432,  # Puerto predeterminado de PostgreSQL
    user="postgres",
    password="password",  # Cambiar por tu contraseña
    database="databases_name"
)

# Migrar todas las tablas
migrator.migrate_all()

# Cerrar conexiones
migrator.close_connections()
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/archenthusiastic/mysql-migrator-postgreesql",
    "name": "mysqlmigratorpostgree",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "archenthusiastic",
    "author_email": "abuawadsantiago@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/96/c8/66c03116e583035c5bf66076bff97b1e0804ea7244d4360caa4811d1f422/mysqlmigratorpostgree-0.2.0.tar.gz",
    "platform": null,
    "description": "# MysqlMigratorPostgree\r\n\r\n## Introducci\u00c3\u00b3n\r\n\r\n```\r\npip install mysqlmigratorpostgreesql\r\n```\r\n**MysqlMigratorPostgree** es una librer\u00c3\u00ada en Python dise\u00c3\u00b1ada para facilitar la migraci\u00c3\u00b3n de bases de datos completas desde **MySQL** hacia **PostgreSQL**. Esta herramienta es ideal para ingenieros de software que buscan una soluci\u00c3\u00b3n automatizada para transferir datos y estructuras de tablas entre estos dos sistemas de gesti\u00c3\u00b3n de bases de datos relacionales.\r\n\r\nLa librer\u00c3\u00ada ofrece:\r\n- Conexi\u00c3\u00b3n sencilla a servidores de MySQL y PostgreSQL.\r\n- Migraci\u00c3\u00b3n automatizada de tablas, incluyendo columnas y tipos de datos.\r\n- Manejo eficiente de conexiones y errores.\r\n- Un dise\u00c3\u00b1o modular y extensible.\r\n\r\n---\r\n\r\n## Diccionario de Palabras Reservadas\r\n\r\nDurante la migraci\u00c3\u00b3n, ciertos tipos de datos en **MySQL** no tienen un equivalente exacto en **PostgreSQL**. Este es un resumen de las conversiones realizadas por la librer\u00c3\u00ada:\r\n\r\n| **Tipo en MySQL**     | **Tipo en PostgreSQL** | **Descripci\u00c3\u00b3n**                                                                 |\r\n|------------------------|------------------------|---------------------------------------------------------------------------------|\r\n| `INT`                 | `INTEGER`             | Enteros de tama\u00c3\u00b1o fijo.                                                        |\r\n| `VARCHAR(n)`          | `TEXT`                | PostgreSQL no requiere l\u00c3\u00admites estrictos para textos.                          |\r\n| `TEXT`                | `TEXT`                | Se mantiene el mismo tipo para textos largos.                                  |\r\n| `FLOAT`               | `REAL`                | Valores de punto flotante.                                                     |\r\n| `DOUBLE`              | `DOUBLE PRECISION`    | Valores de mayor precisi\u00c3\u00b3n en PostgreSQL.                                      |\r\n| `DATE`                | `DATE`                | Fecha est\u00c3\u00a1ndar en formato `YYYY-MM-DD`.                                        |\r\n| `DATETIME`            | `TIMESTAMP`           | Fecha y hora con zona horaria.                                                 |\r\n| `TINYINT(1)`          | `BOOLEAN`             | Interpretado como un valor l\u00c3\u00b3gico (`TRUE` o `FALSE`).                          |\r\n| `ENUM`                | `TEXT`                | Convertido a texto, ya que PostgreSQL no soporta directamente el tipo `ENUM`.  |\r\n\r\n---\r\n\r\n## Detalles del C\u00c3\u00b3digo\r\n\r\n### **Estructura General**\r\n\r\nLa librer\u00c3\u00ada sigue un enfoque modular. Cada funcionalidad est\u00c3\u00a1 definida en un archivo espec\u00c3\u00adfico:\r\n- **`connect_mysql.py`**: Maneja la conexi\u00c3\u00b3n a un servidor MySQL.\r\n- **`connect_postgresql.py`**: Maneja la conexi\u00c3\u00b3n a un servidor PostgreSQL.\r\n- **`migrator.py`**: Orquesta la migraci\u00c3\u00b3n de tablas y datos.\r\n\r\n---\r\n\r\n### **Cambios en los Tipos de Datos**\r\n\r\nLa l\u00c3\u00b3gica para convertir tipos de datos de MySQL a PostgreSQL se encuentra en el archivo `migrator.py`. Aqu\u00c3\u00ad est\u00c3\u00a1 el fragmento clave del c\u00c3\u00b3digo con explicaci\u00c3\u00b3n:\r\n\r\n```python\r\n# Mapeo de tipos de datos\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\"  # Tipo predeterminado si no hay un mapeo espec\u00c3\u00adfico\r\n```\r\n\r\n## C\u00c3\u00b3digo de Ejemplo\r\n\r\nAqu\u00c3\u00ad tienes un ejemplo funcional que muestra c\u00c3\u00b3mo usar la librer\u00c3\u00ada para migrar todas las tablas de una base de datos MySQL a PostgreSQL:\r\n\r\n```python\r\nfrom mysqlmigratorpostgree import MysqlMigratorPostgree\r\n\r\n# Instanciar el migrador\r\nmigrator = MysqlMigratorPostgree()\r\n\r\n# Conectar a MySQL\r\nmigrator.connect_mysql(\r\n    host=\"localhost\",\r\n    port=3306,  # Puerto predeterminado de MySQL\r\n    user=\"root\",\r\n    password=\"password\",  # Cambiar por tu contrase\u00c3\u00b1a\r\n    database=\"databases_name\"\r\n)\r\n\r\n# Conectar a PostgreSQL\r\nmigrator.connect_postgresql(\r\n    host=\"localhost\",\r\n    port=5432,  # Puerto predeterminado de PostgreSQL\r\n    user=\"postgres\",\r\n    password=\"password\",  # Cambiar por tu contrase\u00c3\u00b1a\r\n    database=\"databases_name\"\r\n)\r\n\r\n# Migrar todas las tablas\r\nmigrator.migrate_all()\r\n\r\n# Cerrar conexiones\r\nmigrator.close_connections()\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Libreria pensada para migrar datos a postgresql de manera versatil auto modulando simplificado el codigo",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/archenthusiastic/mysql-migrator-postgreesql"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eeaf2fbe723cdb630f2ba698ad4ffa3e86a9924b180236e026b7be5e74dc02b6",
                "md5": "408b2293c21080f418beaf3435417e48",
                "sha256": "0e6d4bc820b821386b7c2fdda8cfb60b3a41ebb832d122c985fc4c5a641fc92a"
            },
            "downloads": -1,
            "filename": "mysqlmigratorpostgree-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "408b2293c21080f418beaf3435417e48",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6525,
            "upload_time": "2024-12-06T03:45:03",
            "upload_time_iso_8601": "2024-12-06T03:45:03.614744Z",
            "url": "https://files.pythonhosted.org/packages/ee/af/2fbe723cdb630f2ba698ad4ffa3e86a9924b180236e026b7be5e74dc02b6/mysqlmigratorpostgree-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "96c866c03116e583035c5bf66076bff97b1e0804ea7244d4360caa4811d1f422",
                "md5": "cdb4b2bc4938c7da6a8825733e6bd766",
                "sha256": "a4fd8b39b455945d02ebd312eff8b95efd2e8d9da3636d9e9e822ac5367143e0"
            },
            "downloads": -1,
            "filename": "mysqlmigratorpostgree-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "cdb4b2bc4938c7da6a8825733e6bd766",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5347,
            "upload_time": "2024-12-06T03:45:05",
            "upload_time_iso_8601": "2024-12-06T03:45:05.197569Z",
            "url": "https://files.pythonhosted.org/packages/96/c8/66c03116e583035c5bf66076bff97b1e0804ea7244d4360caa4811d1f422/mysqlmigratorpostgree-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-06 03:45:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "archenthusiastic",
    "github_project": "mysql-migrator-postgreesql",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mysqlmigratorpostgree"
}
        
Elapsed time: 0.69041s