Skip to main content

logiskip - Logical database migration between RDBMSs

Synopsis

logiskip is a command-line tool written in Python (using SQLAlchemy) that can migrate application data between different RDMSs, e.g. between MySQL and PostgreSQL.

It is modular, with the possibility to define migration logic for applications in separate classes (so-called “loads”).

logiskip can be used for simple tasks like mere copying of tables, but also for more complex tasks (e.g. converting images to another format, converting complex types, etc.).

Installation

logiskip can be installed using pip. In doing so, the needed database engines can be passed as extras. To install logiskip with the ability to convert between MySQL and PostgreSQL:

pip3 install 'logiskip[mysql,postgres]'

Usage

The package installs the logiskip command, which takes the following options:

--source TEXT        URI of source database
--destination TEXT   URI of destination database
--load-name TEXT     Name of load plugin for migrated application
--load-version TEXT  Version of migrated application/schema
--dry-run            Roll back transaction instead of commiting
-v, --verbosity LVL  Either CRITICAL, ERROR, WARNING, INFO or DEBUG.
--help               Show this message and exit.

The following example migrates an installation of Roundcube 1.4.1 from MySQL to PostgreSQL:

logiskip --source 'mysql://roundcube:secret@localhost/roundcube' \
         --destination 'postgresql://roundcube:secret@localhost/roundcube' \
         --load-name roundcube --load-version 1.4.1

Loads

Loads in logiskip define migrations for a single application within a version constraint. Here is an artificial example:

from logiskip.load import BaseLoad
from sqlalchemy.orm import sessionmaker

class ExampleLoad(BaseLoad, name="example", version_constraint=">=1.0,<2.0"):
    """Load for the application example within the semver constraint 1.x"""

    # Table map for all migrations
    # Tables mapped to None are skipped
    default_tables = {
        "cache": None  # Do not migrate the cache table
    }

    # Table map for migrating from MySQL to PostgreSQL
    postgresql_mysql_tables = {
        "geolocations": None,  # Application supports GIS only in PostgreSQL
        "user": "users"  # Historic naming issue
    }

    # Field map for the "user" table when migrating from PostgreSQL to MySQL
    postgresql_mysql_fields_user = {
        "geolocation_fk": None  # See above
    }

    def mysql_postgresql_row_users(self, src_table, src_dict):
        """Do reverse-geolocation for user addresses when migrating to PostgreSQL"""
        # First, do the default conversion
        dest_row = super()._convert_row_default(src_table, src_dict)

        # Get geolocation for address
        lat, lon = geocoder.reverse(dest_row["address"])

        # Use SQLAlchemy to create a new geolocation entry
        session = sessionmaker(bind=self.dest_engine)()
        geoloc = self.dest_base.classes.geolocations(lat=lat, lon=lon)
        session.commit()

        # Set foreign key to geolocation
        dest_row["geolocation_fk"] = geoloc.id
        return dest_row

    # More examples include:
    #   x_y_field_tablename__fieldname(self, src_value) - Do a conversion on a single field value
    #   x_y_table_tablename - Do the full table conversion manually
    # x_y can be default in all places to be used for any migration pair

Credits

logiskip was sponsored by:

Copyright 2021 Dominik George <dominik.george@credativ.de>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Metadata

Release files for logiskip 0.1.0.post1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logiskip 0.1.0.post1
File Size Uploaded
logiskip-0.1.0.post1.tar.gz 11.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for logiskip 0.1.0.post1
File Interpreter ABI Platform
logiskip-0.1.0.post1-py3-none-any.whl Python 3 none any Details

Total release size: 27.0 kB

Release files / logiskip-0.1.0.post1.tar.gz

Download URL logiskip-0.1.0.post1.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
442b613142e42252a6d114a96526d49ed2ed73b5e39103bf5421f05e88ad168a
BLAKE2b-256 checksum
How to use checksums
8db41c06807cdda0928c52024708e9fdb145d676ee4693a0ce91d1e70fd8981d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

Release files / logiskip-0.1.0.post1-py3-none-any.whl

Download URL logiskip-0.1.0.post1-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d49fa2e421bc145896be7f8aa84cae77e396c2106fa83eb50eff7b26739b979
BLAKE2b-256 checksum
How to use checksums
3e6818c588adde5ec868893619f105c6daed3c3a19c7ee87c0b3d7d333f7a058
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

Release history Release notifications | RSS feed

This release

0.1.0.post1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page