Categorygithub.com/limoli/dbshift-core
modulepackage
0.0.0-20200521200304-4b732b0e3fc4
Repository: https://github.com/limoli/dbshift-core.git
Documentation: pkg.go.dev

# README

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

KeyDescriptionValue example
DBSHIFT_ABS_FOLDER_MIGRATIONSWhere migrations are created and stored./srv/app/migrations
DBSHIFT_OPTION_IS_CREATE_DISABLEDDisable create command (useful on production).true / false (default)
DBSHIFT_OPTION_IS_DOWNGRADE_DISABLEDDisable downgrade command (useful on production).true / false (default)
DBSHIFT_OPTION_IS_UPGRADE_DISABLEDDisable 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].

CodeDescription
1When 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

# Functions

NewCmd create a shell-commander object based on database interface and environmental configuration.
PrintFailure prints a formatted text adding a special failure character.
PrintSuccess prints a formatted text adding a special success character.

# Structs

Migration is a structure used to group the essential information regarding the database-schema migration.
Status is a structure used to identify the current (latest) migration version and type executed on database.