migdb

command module
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: MIT Imports: 3 Imported by: 0

README

migdb - Database Migration CLI Tool

migdb is a easy-to-use database migration tool written in Golang. It allows you to perform forward and backward migrations on your database, and generates migration files on the specified folder. Migdb supports sqlite3 (default), postgresql, mysql and in future, other databases.

Installation

Install migdb with the following go command:

go install github.com/adharshmk96/[email protected]

Usage

migdb [?:flags] [command] [?:params]

Example:

Generate config file

migdb mkconfig

Generate some migration files

migdb -d sqlite3 generate 5 --fill

Perform forward migration

migdb -d sqlite3 up 

Check history of migrations

migdb -d sqlite3 history

Perform backward migration

migdb -d sqlite3 down 2
Commands
mkconfig    Generates configuration file in the working directory
generate    Generate migration files on the specified folder, staring from the next number in the sequence
up          Perform the foward migration ( runs all files after the previously applied migrations )
down        Perform the backward migration ( runs all files from the last applied migration in reverse order )
history     Show migration history from the database
clean       Cleans un applied migration files from the directory
purge       Wipes entire database, performs migration down and deletes migration table (use with caution)
completion  Generate the autocompletion script for the specified shell
help        Help about any command
Flags
-d, --database string     Database to use: pg, sqlite3 (default sqlite3)
-p, --folderPath string   Path to the migrations directory (default "./migrations")
-h, --help                help for migdb

generate
  --fill   Fill the migration files with default template 

Migration Folder Structure

The migration folder consists of two directories, up and down, for forward and backward migrations respectively.

Config file

The config file can be generated with the migdb mkconfig command. migdb.yaml file should be placed in the run directory. This file contains the database connection details and the path to the migration folder.

folderPath: "migrations"
database: "sqlite3"

postgresql:
  host: "localhost"
  port: 5432
  user: "postgres"
  password: "postgres"
  dbname: "postgres"

sqlite3:
  path: "migdb.db"

mysql:
  host: "localhost"
  port: 3306
  user: "mysql"
  password: "mysql"
  dbname: "mysql"
  

Migration Record

A migration record will be created in the database to store the migration history. This helps migdb to keep track of the applied migrations and allows you to perform backward and forward migrations smoothly.

Migration record will have name, type and created timestamp ( can be accessed with migdb history command )

Note

Please use the following commands with caution,

  • purge command performs migration down, and deletes the migration table.
  • clean command removes all unapplied migration files.

Dev and Release migdb

  • update the versions using make patch / minor / major to ensure everything is set.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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