Skip to main content

Base Migrator

PyPI

Liquibase's almost compatible tool that works very similary, but just using only Python code.

Installation

To use at a MySQL database:

$ pip install basemigrator[mysql]

To use at a PostgreSQL database:

$ pip install basemigrator[postgresql]

Usage

There's basicly two rules to use this tool:

  1. The changelog file MUST in the same folder as the migrations
  2. The changelog file MUST follow the expected format specified in the documentation
  3. The migration SQL file MUST have a set of metadata to be applied properly

About the first rule, it's simple, follow this folder structure and you will be fine:

migrations/
├── changelog.xml
├── Table1
│   └── Table1-createtable.sql
└── Table2
    └── Table2-createtable.sql

The second rule applies for the changelog file format, which depending on her extension, MUST be one of these two:

XML

<?xml version="1.0" encoding="UTF-8"?>

<databaseChangeLog>
  <include file="Table1/Table1-createtable.sql" relativeToChangelogFile="true" />
  <include file="Table2/Table2-createtable.sql" relativeToChangelogFile="dev, prod" />
</databaseChangeLog>

YAML

- file: Table1/Table1-createtable.sql
- file: Table2/Table2-createtable.sql
  context: dev, prod

The third rule specifies that the migration must have a set of metadata, which are:

--liquibase formatted sql
--changeset <author>:<migration-id>

CREATE TABLE Table1();

The configuration object passed as a parameter for the function that will execute the migrations should have a field named config that at least implements the __get__() method and have the following key-values:

class App:

    def __init__(self):
        self.config = {
            'DB_USER': 'user', # the database user
            'DB_PASSWORD': 'password', # the database password
            'DB_HOST': 'localhost', # the database host
            'DB_DATABASE': 'foo' # the database name
        }

To call the migrate() function, three parameters must be given, they are:

from basemigrator import migrate

migrate(
  app=app, # the app configuration object
  changelog='/path/to/migrations', # the full path of the migrations folder
  context='dev' # the context which the migrations will be applied
)

Supported databases

  • MySQL
  • PostgreSQL

PostgreSQL

Currently, procedures create statements are not supported.

TODO

  • CI/CD
    • code linting
    • publish package to pypi
  • Contributing section
  • tests/

Release files for basemigrator 0.1.3

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

Source distribution (sdist)

Source distribution for basemigrator 0.1.3
File Size Uploaded
basemigrator-0.1.3.tar.gz 6.1 kB Details

Built distribution (wheel)

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

Total release size: 13.0 kB

Release files / basemigrator-0.1.3.tar.gz

Download URL basemigrator-0.1.3.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c3ac8f9f7c448f8b4da9a2930952cf661a4ce2c0009151cb0eb2e52534e0e5e9
BLAKE2b-256 checksum
How to use checksums
c9b329a0c35eb0a5dc3c8f40f5122fffe9289c92d70bc3e5ab81a116665c14cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.7.4

Release files / basemigrator-0.1.3-py3-none-any.whl

Download URL basemigrator-0.1.3-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa2ffbc2b4d237c16b447cc6de71f5c9ecede43c2635b1102f5884daea54a481
BLAKE2b-256 checksum
How to use checksums
afd7c55c9c46263c1b18cd1b5f01314ed05c21e391d42300b90db6fd456fc486
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

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