Skip to content

limoli/dbshift-core

Repository files navigation

DbShift Core

DbShift Core provides simple and light logic for the management of database-schema migrations. You will be able to create migrations, check the current db status, decide to upgrade or downgrade easily. It can be easily implemented with specific database clients.

GoDoc Build Status Go Report Card Maintainability Test Coverage License

Install

DbShift Core aims to provide logic and not an installable command. You can use a DbShift Client implementation according to your database:

Commands

Set your configuration

Create migration

It creates two files ($timestamp.down.sql and $timestamp.up.sql) at your migrations folder.

dbshift create my-migration-description

Status

Check status of your migrations.

dbshift status

Upgrade

Upgrade migrations.

dbshift upgrade
dbshift upgrade <toInclusiveMigrationVersion>

Downgrade

Downgrade migrations.

dbshift downgrade
dbshift downgrade <toInclusiveMigrationVersion>

Configuration

Key Description Value example
DBSHIFT_ABS_FOLDER_MIGRATIONS Where migrations are created and stored. /srv/app/migrations
DBSHIFT_OPTION_IS_CREATE_DISABLED Disable create command (useful on production). true / false (default)
DBSHIFT_OPTION_IS_DOWNGRADE_DISABLED Disable downgrade command (useful on production). true / false (default)
DBSHIFT_OPTION_IS_UPGRADE_DISABLED Disable upgrade command (useful on production). true / false (default)

This configuration represents the basic configuration for the DbShift Core. More configurations can be offered by the single DbShift Client.

Write good migrations

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

Exit codes

The following error-codes interval is reserved for core usage: [1, 90].

Code Description
1 When no command is passed in the no-interactive mode.

Client implementation

Exit codes

The client implementation interval is [100,255].

Environment

The environment variables must have the following prefix: DBSHIFT_CLI_<DBTYPE>.

Example for MySQL:

  • Prefix: DBSHIFT_CLI_MYSQL
  • Variables: DBSHIFT_CLI_MYSQL_X, DBSHIFT_CLI_MYSQL_Y, DBSHIFT_CLI_MYSQL_Z