Skip to main content

database-migration-tool

Database migration made simple.

Database support

  • MySQL
  • SQLite

Functions

Validations

  • Only run sql querys that has not been run before
  • Checks that all checksum are same on installed and on the scripts
  • New versions can't be inserted between two installed scripts

Command line

<command> --changelog-file=config.yaml migrate

commands:

command Description
clean
info
migrate

Changelog file

yaml file with changelog settings for the database migrations

example.yaml

database:
  database_plugin: mysql
  host: localhost
  port: 3306
  username: ${env:MYSQL_USER}
  password: ${env:MYSQL_PASS}

xxxxxxxx:
  allow_clean: True

databaseMigrations:
  - changeSet: 1
    author: Mike <mike@email.com>
    changes:
    sqlFile: baseline.sql
  - changeSet: 2
    author: Matt <matt@email.com>
    changes:
    sqlFile: test.sql
    parameters:
      - userName: test
      - email: test@email.com
  - changeSet: 3
    author: Matt <matt@email.com>
    changes:
    scriptFile: test.py

parameters:
  - tableName: users
  - name: test

baseline.sql

--- sql with parameter inputs from changelog file
CREATE TABLE ${tableName} (
  name VARCHAR(30) NOT NULL,
  PRIMARY KEY(name)
);

INSERT INTO ${tableName} (name) VALUES ('${name}');

--- sql with parameter input from enviroment variables
CREATE TABLE ${env:TABLE_NAME} (
  test VARCHAR(10) NOT NULL,
  PRIMARY KEY(test)
);

--- normal sql
CREATE TABLE email (
  email VARCHAR(255) NOT NULL,
  PRIMARY KEY(email)
);

Tables

database-change-log

Table for tracking changes to the database

Column Data type Description
id INT ID
description VARCHAR(255) description from the script
script VARCHAR(255) filename of the script
checksum VARCHAR(64) SHA256 checksum of the script file
installed_on TIMESTAMP date and time when successfully migrtated
total_querys INT total sql querys in file
done_querys INT number of last successful query
success INT 1 for success 0 for failure

database-change-lock

Table for storing database lock to prevent only one instanse of xxx to be running against the database

Column Data type Description
id INT ID of the lock
locked INT 1 if locked otherwise 0
granted DATETIME Date and time lock was granted
locked_by VARCHAR(255) DB username

Metadata

Release files for db-migration-tool 0.1.1

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

Source distribution (sdist)

Source distribution for db-migration-tool 0.1.1
File Size Uploaded
db-migration-tool-0.1.1.tar.gz 20.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for db-migration-tool 0.1.1
File Interpreter ABI Platform
db_migration_tool-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 44.7 kB

Release files / db-migration-tool-0.1.1.tar.gz

Download URL db-migration-tool-0.1.1.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5b4e4e893b77d1696908184ddefce9e2714ff9467f7ed1883066d932b7371f6e
BLAKE2b-256 checksum
How to use checksums
0818d25d2153edf2b0bb6da2113616bb629d531e3b6dc8a4a79e8daf5588d34b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / db_migration_tool-0.1.1-py3-none-any.whl

Download URL db_migration_tool-0.1.1-py3-none-any.whl
Size 24.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ebf94a596014282b32f8b65fb363bc920fa109222086017aa4424237e15c48a9
BLAKE2b-256 checksum
How to use checksums
36694a829000b24f646e3b4e89e8b099fce386cfdef044d2d01449ed619a7cb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.1.1 This release

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