Skip to main content

A command line utility

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

db-migration-tool-0.1.1.tar.gz (20.6 kB view hashes)

Uploaded Source

Built Distribution

db_migration_tool-0.1.1-py3-none-any.whl (24.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page