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 pg (default) and in future, other databases.
Installation
Install migdb with the following go command:
go install github.com/adharshmk96/migdb@v0.0.5
Usage
migdb [?:flags] [command] [?:params]
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 postgresql)
-p, --folderPath string Path to the migrations directory (default "./migrations")
-h, --help help for migdb
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: "postgresql"
postgresql:
host: "localhost"
port: 5432
user: "postgres"
password: "postgres"
dbname: "postgres"
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 clean command with caution, as it performs migration down, and deletes the migration table.