gograte

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 14 Imported by: 0

README

Gograte: Database Migration Tool

Motivations

This project is highly inspired by Goose which is also a database migration tool. I was susprised by the simplicity of this tool. So, I wanted to build by myself. This project includes most of the features Goose offers.

Install
go install github.com/Shin-Thant/gograte/cmd/gograte@latest

This will install the gograte binary to your $GOPATH/bin directory.

Guides

Move to cmd/gograte directory and run go install. Then you are good to go. Move to your project and use those commands.

  1. Init your migration.
    gograte init
    
  2. Create your migration sql file.
    gograte create first
    
    This will create sql file in this format [timestamp]-[name].sql
  3. Migrate with this commands.
    gograte migrate [db_driver] [db_url] [action]
    
    Action option can be the followings.
    1. up
    2. up-one
    3. up-to (example up-to [version])
    4. down
    5. down-one
    6. down-to (example down-to [version])
  4. Help
    gograte --help
    

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ACTION = 3
View Source
var DB_URL = 2
View Source
var DRIVER = 1

argument indexes

View Source
var MIGRATION = 1

argument indexes

View Source
var QUERY_ALL_MIGRATIONS = `SELECT * FROM _gograte_db_versions ORDER BY created_at ASC;`
View Source
var QUERY_APPLIED_MIGRATIONS = `SELECT * FROM _gograte_db_versions WHERE is_applied = true ORDER BY created_at DESC;`
View Source
var QUERY_NON_APPLIED_MIGRATIONS = `SELECT * FROM _gograte_db_versions WHERE is_applied = false ORDER BY created_at ASC;`
View Source
var QUERY_ONE_APPLIED_MIGRATION = `SELECT * FROM _gograte_db_versions WHERE is_applied = true ORDER BY created_at DESC LIMIT 1;`
View Source
var UsageMessage = `` /* 1144-byte string literal not displayed */
View Source
var VERSION = 4

Functions

func Create

func Create(args []string)

func CreateMigrationTableIfNotExist

func CreateMigrationTableIfNotExist(db *sql.DB) (sql.Result, error)

func GetSQLDriver

func GetSQLDriver(driver string) string

func Init

func Init()

func Migrate

func Migrate(args []string)

func NewMigrationRecord

func NewMigrationRecord() *migrationRecord

func Status

func Status(args []string)

func ValidateDbDriver

func ValidateDbDriver(inputDriver string) bool

func ValidateMigrationFilePaths

func ValidateMigrationFilePaths(paths []string) []migrationFile

Types

type ValidData

type ValidData []string
var ACTIONS ValidData = []string{"up", "down", "up-one", "down-one", "up-to", "down-to"}
var DB_DRIVERS ValidData = []string{"mysql", "postgres", "sqlite3"}

func (*ValidData) String

func (v *ValidData) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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