Skip to content
/ dbshift Public

DbShift is a light database migrations tool with the goal of simplicity.

License

Notifications You must be signed in to change notification settings

limoli/dbshift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DbShift

DbShift is a simple database migrations tool with the goal of simplicity. You will be able to create migrations, check the current db status, decide to upgrade or downgrade easily.

This project is deprecated and no longer supported.

Dbshit has been divided into several projects based on Dbshift Core.

deprecated GoDoc Build Status Go Report Card Maintainability Test Coverage

Install

go get github.com/limoli/dbshift

Tutorial

  1. Create your configuration file and set its path using DBSHIFT_CONFIG

  2. Initialise your configuration:

dbshift init
  1. Create migration. The following command will create two files $uuid.down.sql and $uuid.up.sql at your migrations folder.
dbshift create my-migration-description
  1. Check status of your current database.
dbshift status
  1. Upgrade migrations.
dbshift upgrade
  1. Downgrade migrations.
dbshift downgrade
  1. Get list of available upgrade migrations.
dbshift migrations-upgrade
  1. Get list of available downgrade migrations.
dbshift migrations-downgrade
  1. Get settings info
dbshift info
  1. Import missing migrations. It is useful when you work on different initialised databases.
dbshift refresh

Write good migrations

  1. Queries must be database name agnostic
  2. SRP according to your description
  3. Write both upgrade and downgrade migrations

Configuration

All you need is an environment variable DBSHIFT_CONFIG which represents the path where dbshift will find:

  • a configuration file dbshift.yaml written by you
  • an autogenerated lockfile managed from dbshift
export DBSHIFT_CONFIG=/absolutePath/dbshift.yaml

The configuration file has the following structure:

db:
  type: mysql
  migration:
    path: /absolutePath/migrations
    pathEnv: "MYSQL_MIGRATIONS_PATH"
  connection:
    name:
      env: MYSQL_DATABASE
      value:
    user:
      env: MYSQL_USER
      value:
    password:
      env: MYSQL_PASSWORD
      value:
    host:
      env: MYSQL_HOST
      value:
    port:
      env: MYSQL_PORT
      value: 3306

The connection object is composed by fields which values can be set from the value field or from an environment variable declared in the env field.

The environment variable overrides the value if set.

export MYSQL_DATABASE=test
export MYSQL_USER=root
export MYSQL_PASSWORD=root
export MYSQL_HOST=127.0.0.1
export MYSQL_PORT=3306

DB compatibility

At the moment the project is focused only on MySQL, but it is opened to implementations.

Future implementations

  1. Improve test coverage
  2. Add possibility to upgrade/downgrade to a specific migration
  3. Add command to restore dbshift in case of transactional errors
  4. Add command to remove a migration
  5. Add command to get list of all migrations with description and uuid reference