sql-migrator

command module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2021 License: MIT Imports: 14 Imported by: 0

README

sql-migrator

Version license Coverage Status Go Report Card

Golang utility for managing sql migrations using.

The package includes the following drivers: postgres, mysql, sqlite3.

Usage

Installation and setup
go get -u github.com/malyg1n/sql-migrator

Create a file .env by copying from .env.example and specify your database settings. In the same file, specify the folder for migrations (migrations in root of project by default). After that, tou need to run the command:

sql-migrator init

This command creates table and directory (if not exists) to store your migrations.

Create migration files.

At the root of the project, you need to run a command with the following signature:

sql-migrator create migration-name

Like this:

sql-migrator create create-users-table

After that, two files will appear in the migrations' folder at the root of the project.

00001-create-users-table-up.sql
00001-create-users-table-down.sql

They need to write SQL code for rolling and rolling back migration, respectively.

See migrations' examples here.

Migrations

To roll out migrations, use the command:

sql-migrator up

And to rollback:

sql-migrator down

Complete cleaning of all migrations and roll out them over again:

sql-migrator refresh

Complete cleaning of all migrations:

sql-migrator clean

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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