https://github.com/limoli/dbshift-core
A light migration logic expandable to different databases.
https://github.com/limoli/dbshift-core
command-line-tool dbmigration migration-tool migrations
Last synced: 5 months ago
JSON representation
A light migration logic expandable to different databases.
- Host: GitHub
- URL: https://github.com/limoli/dbshift-core
- Owner: limoli
- License: mit
- Created: 2019-09-27T08:21:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-25T05:57:56.000Z (over 3 years ago)
- Last Synced: 2024-06-19T05:43:07.336Z (almost 2 years ago)
- Topics: command-line-tool, dbmigration, migration-tool, migrations
- Language: Go
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
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.
[](https://godoc.org/github.com/limoli/dbshift-core)
[](https://travis-ci.org/limoli/dbshift-core)
[](https://goreportcard.com/report/github.com/limoli/dbshift-core)
[](https://codeclimate.com/github/limoli/dbshift-core/maintainability)
[](https://codeclimate.com/github/limoli/dbshift-core/test_coverage)
[](https://raw.githubusercontent.com/github.com/limoli/dbshift-core/LICENSE)
## Install
DbShift Core aims to provide logic and **not an installable command**.
You can use a **DbShift Client** implementation according to your database:
- [MySQL client](https://github.com/limoli/dbshift-cli-mysql)
## Commands
Set your [configuration](#configuration)
#### Create migration
It creates two files (`$timestamp.down.sql` and `$timestamp.up.sql`) at your migrations folder.
```bash
dbshift create my-migration-description
```
#### Status
Check status of your migrations.
```bash
dbshift status
```
#### Upgrade
Upgrade migrations.
```bash
dbshift upgrade
```
```bash
dbshift upgrade
```
#### Downgrade
Downgrade migrations.
```bash
dbshift downgrade
```
```bash
dbshift downgrade
```
## 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](https://en.wikipedia.org/wiki/Single_responsibility_principle) 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_`.
Example for `MySQL`:
- Prefix: `DBSHIFT_CLI_MYSQL`
- Variables: `DBSHIFT_CLI_MYSQL_X`, `DBSHIFT_CLI_MYSQL_Y`, `DBSHIFT_CLI_MYSQL_Z`