dbshiftcore

package module
v0.0.0-...-4b732b0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2020 License: MIT Imports: 10 Imported by: 0

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCmd

func NewCmd(db iDatabase) (*cmd, error)

NewCmd create a shell-commander object based on database interface and environmental configuration.

func PrintFailure

func PrintFailure(text string, args ...interface{})

PrintFailure prints a formatted text adding a special failure character

func PrintSuccess

func PrintSuccess(text string, args ...interface{})

PrintSuccess prints a formatted text adding a special success character

Types

type Migration

type Migration struct {
	Version string
	Name    string
	Type    migrationType
}

Migration is a structure used to group the essential information regarding the database-schema migration.

type Status

type Status struct {
	Version string
	Type    migrationType
}

Status is a structure used to identify the current (latest) migration version and type executed on database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL