Skip to content

ewwwwwqm/mig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Database migration utility

Godoc Reference Build Status Go Report Card

Database migration utility provides a single interface for database management.

Current version: 0.1.0

Included drivers:

  • MySQL
  • SQLite3
  • Postgres

Available commands:

  • create
  • describe
  • drop
  • sql

TODO

  • Postgres
  • Create/update/set/delete configuration files for connections
  • Dump database/tables command
  • Pack/unpack dumped database files
  • Merge databases/tables command
  • Webserver api for REST and security

Usage help

Display help information:

$ ./mig -h
Database migration utility
v0.1.0

Visit github.com/ewwwwwqm/mig for more information.

Options:

  -h, --help      display help information
  -v, --version   display current version
      --drivers   display available drivers

Commands:

  create     Creates database
  describe   Describes table
  drop       Drops database
  sql        Prompts SQL queries

Display create command help:

$ ./mig create -h
Creates database

Options:

  -h, --help                         display help information
      --drv, --driver               *database driver
      --host[=127.0.0.1]             hostname or ip
      --protocol[=tcp]               communication protocol
      --port[=3306]                  database port
      --db, --dbname                *name of the database
  -u, --user                         username
  -p, --password                     password
      --charset[=utf8]               character set
      --dbpath[=./]                  database path
      --tbl, --table[=scheme_info]   table name
      --sslmode[=disable]            SSL mode

Create a database using prompt:

$ ./mig create

Mig prompts you to fill required database parameters:

Database driver: mysql
Database name: new_db
Database username: root
Database password:

After filling required parameters Mig attempts to create a database.

Check the result and operation execution time:

Connection query:
root:123@tcp(127.0.0.1:3306)/?charset=utf8

SQL:
CREATE DATABASE new_db CHARACTER SET utf8;
USE new_db;

DONE (11.131832ms)

If operation fails, Mig outputs database error message:

Connection query:
root:123@tcp(127.0.0.1:3306)/?charset=utf8

SQL:
CREATE DATABASE new_db CHARACTER SET utf8;

Error 1007: Can't create database 'new_db'; database exists

Same example using SQLite3 driver:

$ ./mig create
Database driver: sqlite3
Database name: new_db
Database username: root
Database password:

Connection query:
./new_db.db

DONE (17.587µs)

Same example using Postgres driver:

$ ./mig create
Database driver: postgres
Database name: new_db
Database username: postgres
Database password:

Connection query:
host=127.0.0.1 user=postgres password=newPassword sslmode=disable

SQL:
CREATE DATABASE new_db OWNER postgres ENCODING 'UTF8';

DONE (335.11233ms)

Manually create a table and insert data using internal SQL editor:

$ ./mig sql --driver=mysql -u=root -p=123 --dbname=new_db

Connection query:
root:123@tcp(127.0.0.1:3306)/new_db?charset=utf8

After successful connection Mig prompts to enter SQL:

For exit enter exit or \q command.

mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20));

DONE (9.864381ms)
mysql> INSERT INTO pet VALUES ("cat", "max");

DONE (11.864013ms)
mysql> SELECT * FROM pet;

{ 1/1
  name: cat
  owner: max
}

Fetched 1 result(s).

DONE (9.593785ms)
mysql> exit

Describe table command:

$ ./mig describe --driver=mysql -u=root -p=123 --dbname=new_db --tbl=pet

Connection query:
root:123@tcp(127.0.0.1:3306)/new_db2?charset=utf8

SQL:
DESCRIBE pet;

Result:
{ 1/2
  Default:
  Extra:
  Field: name
  Key:
  Null: YES
  Type: varchar(20)
},
{ 2/2
  Default:
  Extra:
  Field: owner
  Key:
  Null: YES
  Type: varchar(20)
}

Fetched 2 result(s).

DONE (14.334859ms)

Drop database command:

$ ./mig drop --driver=mysql -u=root -p=123 --dbname=new_db

Connection query:
root:123@tcp(127.0.0.1:3306)/?charset=utf8

SQL:
DROP DATABASE new_db;

DONE (12.676195ms)

Thanks

About

Database migration utility

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages