migo

package module
v0.0.0-...-ca6c90e Latest Latest
Warning

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

Go to latest
Published: May 20, 2019 License: MIT Imports: 15 Imported by: 0

README

Install


go get -u github.com/meta-closure/migo/cmd/migo

Usage

Easy to migrate.

migo -y /path/to/schema.yml -s /path/to/internal.yml -d /path/to/dbconig.yml -e environment run

You can see the details of what migo does.

migo -y /path/to/schema.yml -s /path/to/internal.yml -d /path/to/dbconig.yml -e environment plan

Sample Schema Description

Database configure Sample

default:
    user: sample user
    passwd: passwd
    addr: host:port
    dbname: db

production:
    user: hoge
    passwd: hoge
    addr: host:port
    dbname: db

master:
    user: foo
    passwd: foo
    addr: host:port
    dbname: db

Table Configuration Sample

key:
    name: sample
    primary_key:
        pk_name:
            - pk1
            - pk2
    index:
        index_name:
            - index1
            - index2

Column Configuration Sample


column:
    not_null: true
    name: column_sample
    foreign_key:
        name: fk_id(should be unique)
        target_table: #/definition/table/path
        target_column: column_key

migo support some flags.

  • auto_increment(bool)
  • auto_update(bool, for datetime or timestamp type column)
  • not_null(bool)
  • unique(bool)
  • default

How to Setup to use migo

migo -d database.yml -e develop init

Seeding


# table
foo_table:
      # column
    - bar: 1
      hoge: hoge
    - other: 111
      hoge: hogehoge

# other table
bar:
    - hoge: hogehoge

Test

Need MySQL docker container.

./bin/test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Announce

func Announce(ops Operations, db DB)

func Init

func Init(op InitOption) error

func JoinWithComma

func JoinWithComma(list []string, prefix, suffix string) string

func NewMigrateOptionInvalidError

func NewMigrateOptionInvalidError() error

func NewMySQLConfig

func NewMySQLConfig(db DB) mysql.Config

func NewOptionEmptyError

func NewOptionEmptyError(op string) error

func Plan

func Plan(op MigrateOption) error

func ReadSchema

func ReadSchema(op MigrateOption) (*hschema.HyperSchema, error)

func Run

func Run(op MigrateOption) error

func Seed

func Seed(op SeedOption) error

func Wait

func Wait(op WaitOption) error

Types

type AddColumn

type AddColumn struct {
	Column Column
	Table  Table
}

func (AddColumn) Query

func (op AddColumn) Query() string

func (AddColumn) RollBack

func (op AddColumn) RollBack() string

func (AddColumn) String

func (op AddColumn) String() string

type AddForeignKey

type AddForeignKey struct {
	ForeignKey ForeignKey
}

func (AddForeignKey) Query

func (op AddForeignKey) Query() string

func (AddForeignKey) RollBack

func (op AddForeignKey) RollBack() string

func (AddForeignKey) String

func (op AddForeignKey) String() string

type AddIndex

type AddIndex struct {
	Table Table
	Index Key
}

func NewAddIndex

func NewAddIndex(t Table, k Key) AddIndex

func (AddIndex) Query

func (op AddIndex) Query() string

func (AddIndex) RollBack

func (op AddIndex) RollBack() string

func (AddIndex) String

func (op AddIndex) String() string

type AddPrimaryKey

type AddPrimaryKey struct {
	Table      Table
	PrimaryKey Key
}

func NewAddPrimaryKey

func NewAddPrimaryKey(t Table, k Key) AddPrimaryKey

func (AddPrimaryKey) Query

func (op AddPrimaryKey) Query() string

func (AddPrimaryKey) RollBack

func (op AddPrimaryKey) RollBack() string

func (AddPrimaryKey) String

func (op AddPrimaryKey) String() string

type Column

type Column struct {
	Id            string `json:"id"`
	Name          string `json:"name"`
	Type          string `json:"type"`
	Unique        bool   `json:"unique"`
	AutoIncrement bool   `json:"auto_increment"`
	AutoUpdate    bool   `json:"auto_update"`
	NotNull       bool   `json:"not_null"`
	Default       string `json:"default"`
}

func NewColumn

func NewColumn(id string) Column

type Columns

type Columns []Column

func (Columns) Len

func (c Columns) Len() int

func (Columns) Less

func (c Columns) Less(i, j int) bool

func (Columns) Swap

func (c Columns) Swap(i, j int)

type ConnectionError

type ConnectionError struct {
	// contains filtered or unexported fields
}

func NewConnectionError

func NewConnectionError(err error) ConnectionError

func (ConnectionError) Error

func (err ConnectionError) Error() string

type CreateTable

type CreateTable struct {
	Table Table
}

func (CreateTable) Query

func (op CreateTable) Query() string

func (CreateTable) RollBack

func (op CreateTable) RollBack() string

func (CreateTable) String

func (op CreateTable) String() string

type DB

type DB struct {
	User   string `json:"user"`
	Passwd string `json:"passwd"`
	Addr   string `json:"addr"`
	DBName string `json:"dbname"`
}

func NewDB

func NewDB(filePath, env string) (DB, error)

func (DB) FormatDBUnspecifiedDSN

func (db DB) FormatDBUnspecifiedDSN() string

func (DB) FormatDSN

func (db DB) FormatDSN() string

type DatabaseConfigure

type DatabaseConfigure struct {
	Config map[string]DB
}

func NewDatabaseConfigure

func NewDatabaseConfigure(filePath string) (DatabaseConfigure, error)

type DropColumn

type DropColumn struct {
	Column Column
	Table  Table
}

func (DropColumn) Query

func (op DropColumn) Query() string

func (DropColumn) RollBack

func (op DropColumn) RollBack() string

func (DropColumn) String

func (op DropColumn) String() string

type DropForeignKey

type DropForeignKey struct {
	ForeignKey ForeignKey
}

func (DropForeignKey) Query

func (op DropForeignKey) Query() string

func (DropForeignKey) RollBack

func (op DropForeignKey) RollBack() string

func (DropForeignKey) String

func (op DropForeignKey) String() string

type DropIndex

type DropIndex struct {
	Table Table
	Index Key
}

func NewDropIndex

func NewDropIndex(t Table, k Key) DropIndex

func (DropIndex) Query

func (op DropIndex) Query() string

func (DropIndex) RollBack

func (op DropIndex) RollBack() string

func (DropIndex) String

func (op DropIndex) String() string

type DropPrimaryKey

type DropPrimaryKey struct {
	Table      Table
	PrimaryKey Key
}

func NewDropPrimaryKey

func NewDropPrimaryKey(t Table, k Key) DropPrimaryKey

func (DropPrimaryKey) Query

func (op DropPrimaryKey) Query() string

func (DropPrimaryKey) RollBack

func (op DropPrimaryKey) RollBack() string

func (DropPrimaryKey) String

func (op DropPrimaryKey) String() string

type DropTable

type DropTable struct {
	Table Table
}

func (DropTable) Query

func (op DropTable) Query() string

func (DropTable) RollBack

func (op DropTable) RollBack() string

func (DropTable) String

func (op DropTable) String() string

type ForeignKey

type ForeignKey struct {
	Name          string                 `json:"name"`
	SourceTable   Table                  `json:"source_table"`
	SourceColumn  Column                 `json:"source_column"`
	TargetTable   Table                  `json:"target_table"`
	TargetColumn  Column                 `json:"column"`
	UpdateCascade bool                   `json:"update_cascade"`
	DeleteCascade bool                   `json:"delete_cascade"`
	Raw           map[string]interface{} `json:"-"`
}

func NewForeignKey

func NewForeignKey(sourceTable Table, sourceColumn Column) ForeignKey

type ForeignKeys

type ForeignKeys []ForeignKey

func (ForeignKeys) Len

func (k ForeignKeys) Len() int

func (ForeignKeys) Less

func (k ForeignKeys) Less(i, j int) bool

func (ForeignKeys) Swap

func (k ForeignKeys) Swap(i, j int)

type InitOption

type InitOption struct {
	ConfigFile  string
	Environment string
}

func NewInitOption

func NewInitOption(c *cli.Context) (InitOption, error)

type Key

type Key struct {
	Target Columns `json:"target"`
	Name   string  `json:"name"`
}

func NewKey

func NewKey(name string) Key

type Keys

type Keys []Key

func (Keys) Len

func (k Keys) Len() int

func (Keys) Less

func (k Keys) Less(i, j int) bool

func (Keys) Swap

func (k Keys) Swap(i, j int)

type Logger

type Logger struct{}

func (Logger) Print

func (l Logger) Print(v ...interface{})

type MigrateOption

type MigrateOption struct {
	FormatType  string
	ConfigFile  string
	StateFile   string
	SchemaFile  string
	Environment string
}

func NewMigrateOption

func NewMigrateOption(c *cli.Context) (MigrateOption, error)

func (*MigrateOption) SetConfigFile

func (op *MigrateOption) SetConfigFile(config string) error

func (*MigrateOption) SetEnvironment

func (op *MigrateOption) SetEnvironment(env string) error

func (*MigrateOption) SetJSONFormatSchema

func (op *MigrateOption) SetJSONFormatSchema(schema string)

func (*MigrateOption) SetStateFile

func (op *MigrateOption) SetStateFile(state string) error

func (*MigrateOption) SetYAMLFormatSchema

func (op *MigrateOption) SetYAMLFormatSchema(schema string)

type MigrateOptionInvalidError

type MigrateOptionInvalidError struct {
}

func (MigrateOptionInvalidError) Error

func (err MigrateOptionInvalidError) Error() string

type Operation

type Operation interface {
	RollBack() string
	Query() string
	String() string
}

func NewAddColumn

func NewAddColumn(t Table, c Column) Operation

func NewAddForeignKey

func NewAddForeignKey(key ForeignKey) Operation

func NewCreateTable

func NewCreateTable(t Table) Operation

func NewDropColumn

func NewDropColumn(t Table, c Column) Operation

func NewDropForeignKey

func NewDropForeignKey(key ForeignKey) Operation

func NewDropTable

func NewDropTable(t Table) Operation

func NewRenameTable

func NewRenameTable(old, new Table) Operation

func NewUpdateColumn

func NewUpdateColumn(t Table, old, new Column) Operation

type Operations

type Operations struct {
	Operation []Operation
	// contains filtered or unexported fields
}

func NewOperations

func NewOperations(currentState, newState State) (Operations, error)

func (*Operations) CreateTables

func (ops *Operations) CreateTables(ts []Table) error

func (*Operations) DropTables

func (ops *Operations) DropTables(ts []Table) error

func (*Operations) UpdateTable

func (ops *Operations) UpdateTable(currentTable, newTable Table) error

type OptionEmptyError

type OptionEmptyError struct {
	Option string
}

func (OptionEmptyError) Error

func (err OptionEmptyError) Error() string

type Records

type Records struct {
	Table string
	Items []map[string]interface{}
}

func NewRecords

func NewRecords(table string, items interface{}) (Records, error)

func (Records) Query

func (r Records) Query() string

type RenameTable

type RenameTable struct {
	CurrentTable Table
	NewTable     Table
}

func (RenameTable) Query

func (op RenameTable) Query() string

func (RenameTable) RollBack

func (op RenameTable) RollBack() string

func (RenameTable) String

func (op RenameTable) String() string

type SeedOption

type SeedOption struct {
	RecordFile  string
	ConfigFile  string
	Environment string
}

func NewSeedOption

func NewSeedOption(c *cli.Context) (SeedOption, error)

type State

type State struct {
	DB         DB          `json:"db"`
	Tables     Tables      `json:"tables"`
	ForeignKey ForeignKeys `json:"foreign_key"`
	UpdatedAt  time.Time   `json:"updated_at"`
}

func NewState

func NewState() State

func NewStateFromSchema

func NewStateFromSchema(root *hschema.HyperSchema) (State, error)

func NewStateFromYAML

func NewStateFromYAML(filePath string) (State, error)

func (State) Sort

func (s State) Sort() State

type Table

type Table struct {
	Id         string  `json:"id"`
	Name       string  `json:"name"`
	PrimaryKey Keys    `json"primary_key"`
	Index      Keys    `json:"index"`
	Column     Columns `json:"column"`
}

func NewTable

func NewTable(id string) *Table

type Tables

type Tables []Table

func (Tables) Len

func (t Tables) Len() int

func (Tables) Less

func (t Tables) Less(i, j int) bool

func (Tables) Swap

func (t Tables) Swap(i, j int)

type UpdateColumn

type UpdateColumn struct {
	Table         Table
	CurrentColumn Column
	NewColumn     Column
}

func (UpdateColumn) Query

func (op UpdateColumn) Query() string

func (UpdateColumn) RollBack

func (op UpdateColumn) RollBack() string

func (UpdateColumn) String

func (op UpdateColumn) String() string

type WaitOption

type WaitOption struct {
	ConfigFile  string
	Environment string
}

func NewWaitOption

func NewWaitOption(c *cli.Context) (WaitOption, error)

Directories

Path Synopsis
bin
cmd

Jump to

Keyboard shortcuts

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