Logical database migration between RDBMSs
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file logiskip-0.1.0.post1.tar.gz
.
File metadata
- Download URL: logiskip-0.1.0.post1.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 442b613142e42252a6d114a96526d49ed2ed73b5e39103bf5421f05e88ad168a |
|
MD5 | 326552c686673d556536d36624e7a560 |
|
BLAKE2b-256 | 8db41c06807cdda0928c52024708e9fdb145d676ee4693a0ce91d1e70fd8981d |
File details
Details for the file logiskip-0.1.0.post1-py3-none-any.whl
.
File metadata
- Download URL: logiskip-0.1.0.post1-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d49fa2e421bc145896be7f8aa84cae77e396c2106fa83eb50eff7b26739b979 |
|
MD5 | 7333d5feec805ae3e40cc21cb141b784 |
|
BLAKE2b-256 | 3e6818c588adde5ec868893619f105c6daed3c3a19c7ee87c0b3d7d333f7a058 |