migrator

package
v5.0.0-beta2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	POSTGRES = "postgres"
	SQLITE   = "sqlite3"
	MYSQL    = "mysql"
)
View Source
const (
	IndexType = iota + 1
	UniqueIndex
)

Variables

View Source
var (
	DB_Bit       = "BIT"
	DB_TinyInt   = "TINYINT"
	DB_SmallInt  = "SMALLINT"
	DB_MediumInt = "MEDIUMINT"
	DB_Int       = "INT"
	DB_Integer   = "INTEGER"
	DB_BigInt    = "BIGINT"

	DB_Enum = "ENUM"
	DB_Set  = "SET"

	DB_Char       = "CHAR"
	DB_Varchar    = "VARCHAR"
	DB_NVarchar   = "NVARCHAR"
	DB_TinyText   = "TINYTEXT"
	DB_Text       = "TEXT"
	DB_MediumText = "MEDIUMTEXT"
	DB_LongText   = "LONGTEXT"
	DB_Uuid       = "UUID"

	DB_Date       = "DATE"
	DB_DateTime   = "DATETIME"
	DB_Time       = "TIME"
	DB_TimeStamp  = "TIMESTAMP"
	DB_TimeStampz = "TIMESTAMPZ"

	DB_Decimal = "DECIMAL"
	DB_Numeric = "NUMERIC"

	DB_Real   = "REAL"
	DB_Float  = "FLOAT"
	DB_Double = "DOUBLE"

	DB_Binary     = "BINARY"
	DB_VarBinary  = "VARBINARY"
	DB_TinyBlob   = "TINYBLOB"
	DB_Blob       = "BLOB"
	DB_MediumBlob = "MEDIUMBLOB"
	DB_LongBlob   = "LONGBLOB"
	DB_Bytea      = "BYTEA"

	DB_Bool = "BOOL"

	DB_Serial    = "SERIAL"
	DB_BigSerial = "BIGSERIAL"
)

Functions

This section is empty.

Types

type AddColumnMigration

type AddColumnMigration struct {
	MigrationBase
	// contains filtered or unexported fields
}

func NewAddColumnMigration

func NewAddColumnMigration(table Table, col *Column) *AddColumnMigration

func (*AddColumnMigration) Column

func (m *AddColumnMigration) Column(col *Column) *AddColumnMigration

func (*AddColumnMigration) Sql

func (m *AddColumnMigration) Sql(dialect Dialect) string

func (*AddColumnMigration) Table

func (m *AddColumnMigration) Table(tableName string) *AddColumnMigration

type AddIndexMigration

type AddIndexMigration struct {
	MigrationBase
	// contains filtered or unexported fields
}

func NewAddIndexMigration

func NewAddIndexMigration(table Table, index *Index) *AddIndexMigration

func (*AddIndexMigration) Sql

func (m *AddIndexMigration) Sql(dialect Dialect) string

func (*AddIndexMigration) Table

func (m *AddIndexMigration) Table(tableName string) *AddIndexMigration

type AddTableMigration

type AddTableMigration struct {
	MigrationBase
	// contains filtered or unexported fields
}

func NewAddTableMigration

func NewAddTableMigration(table Table) *AddTableMigration

func (*AddTableMigration) Sql

func (m *AddTableMigration) Sql(d Dialect) string

type BaseDialect

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

func (*BaseDialect) AddColumnSql

func (db *BaseDialect) AddColumnSql(tableName string, col *Column) string

func (*BaseDialect) AndStr

func (b *BaseDialect) AndStr() string

func (*BaseDialect) CopyTableData

func (db *BaseDialect) CopyTableData(sourceTable string, targetTable string, sourceCols []string, targetCols []string) string

func (*BaseDialect) CreateIndexSql

func (db *BaseDialect) CreateIndexSql(tableName string, index *Index) string

func (*BaseDialect) CreateTableSql

func (b *BaseDialect) CreateTableSql(table *Table) string

func (*BaseDialect) DateTimeFunc

func (db *BaseDialect) DateTimeFunc(value string) string

func (*BaseDialect) Default

func (b *BaseDialect) Default(col *Column) string

func (*BaseDialect) DriverName

func (d *BaseDialect) DriverName() string

func (*BaseDialect) DropIndexSql

func (db *BaseDialect) DropIndexSql(tableName string, index *Index) string

func (*BaseDialect) DropTable

func (db *BaseDialect) DropTable(tableName string) string

func (*BaseDialect) EqStr

func (b *BaseDialect) EqStr() string

func (*BaseDialect) LikeStr

func (b *BaseDialect) LikeStr() string

func (*BaseDialect) OrStr

func (b *BaseDialect) OrStr() string

func (*BaseDialect) QuoteColList

func (db *BaseDialect) QuoteColList(cols []string) string

func (*BaseDialect) RenameTable

func (db *BaseDialect) RenameTable(oldName string, newName string) string

func (*BaseDialect) ShowCreateNull

func (b *BaseDialect) ShowCreateNull() bool

func (*BaseDialect) UpdateTableSql

func (db *BaseDialect) UpdateTableSql(tableName string, columns []*Column) string

type Column

type Column struct {
	Name            string
	Type            string
	Length          int
	Length2         int
	Nullable        bool
	IsPrimaryKey    bool
	IsAutoIncrement bool
	Default         string
}

func (*Column) String

func (col *Column) String(d Dialect) string

func (*Column) StringNoPk

func (col *Column) StringNoPk(d Dialect) string

type ColumnType

type ColumnType string
const (
	DB_TYPE_STRING ColumnType = "String"
)

type CopyTableDataMigration

type CopyTableDataMigration struct {
	MigrationBase
	// contains filtered or unexported fields
}

func NewCopyTableDataMigration

func NewCopyTableDataMigration(targetTable string, sourceTable string, colMap map[string]string) *CopyTableDataMigration

func (*CopyTableDataMigration) IfTableExists

func (m *CopyTableDataMigration) IfTableExists(tableName string) *CopyTableDataMigration

func (*CopyTableDataMigration) Sql

type Dialect

type Dialect interface {
	DriverName() string
	QuoteStr() string
	Quote(string) string
	AndStr() string
	AutoIncrStr() string
	OrStr() string
	EqStr() string
	ShowCreateNull() bool
	SqlType(col *Column) string
	SupportEngine() bool
	LikeStr() string
	Default(col *Column) string
	BooleanStr(bool) string
	DateTimeFunc(string) string

	CreateIndexSql(tableName string, index *Index) string
	CreateTableSql(table *Table) string
	AddColumnSql(tableName string, col *Column) string
	CopyTableData(sourceTable string, targetTable string, sourceCols []string, targetCols []string) string
	DropTable(tableName string) string
	DropIndexSql(tableName string, index *Index) string

	TableCheckSql(tableName string) (string, []interface{})
	RenameTable(oldName string, newName string) string
	UpdateTableSql(tableName string, columns []*Column) string
}

func NewDialect

func NewDialect(name string) Dialect

type DropIndexMigration

type DropIndexMigration struct {
	MigrationBase
	// contains filtered or unexported fields
}

func NewDropIndexMigration

func NewDropIndexMigration(table Table, index *Index) *DropIndexMigration

func (*DropIndexMigration) Sql

func (m *DropIndexMigration) Sql(dialect Dialect) string

type DropTableMigration

type DropTableMigration struct {
	MigrationBase
	// contains filtered or unexported fields
}

func NewDropTableMigration

func NewDropTableMigration(tableName string) *DropTableMigration

func (*DropTableMigration) Sql

func (m *DropTableMigration) Sql(d Dialect) string

type IfTableExistsCondition

type IfTableExistsCondition struct {
	TableName string
}

func (*IfTableExistsCondition) Sql

func (c *IfTableExistsCondition) Sql(dialect Dialect) (string, []interface{})

type Index

type Index struct {
	Name string
	Type int
	Cols []string
}

func (*Index) XName

func (index *Index) XName(tableName string) string

type Migration

type Migration interface {
	Sql(dialect Dialect) string
	Id() string
	SetId(string)
	GetCondition() MigrationCondition
}

type MigrationBase

type MigrationBase struct {
	Condition MigrationCondition
	// contains filtered or unexported fields
}

func (*MigrationBase) GetCondition

func (m *MigrationBase) GetCondition() MigrationCondition

func (*MigrationBase) Id

func (m *MigrationBase) Id() string

func (*MigrationBase) SetId

func (m *MigrationBase) SetId(id string)

type MigrationCondition

type MigrationCondition interface {
	Sql(dialect Dialect) (string, []interface{})
}

type MigrationLog

type MigrationLog struct {
	Id          int64
	MigrationId string
	Sql         string
	Success     bool
	Error       string
	Timestamp   time.Time
}

type Migrator

type Migrator struct {
	Logger log.Logger
	// contains filtered or unexported fields
}

func NewMigrator

func NewMigrator(engine *xorm.Engine) *Migrator

func (*Migrator) AddMigration

func (mg *Migrator) AddMigration(id string, m Migration)

func (*Migrator) GetMigrationLog

func (mg *Migrator) GetMigrationLog() (map[string]MigrationLog, error)

func (*Migrator) MigrationsCount

func (mg *Migrator) MigrationsCount() int

func (*Migrator) Start

func (mg *Migrator) Start() error

type Mysql

type Mysql struct {
	BaseDialect
}

func NewMysqlDialect

func NewMysqlDialect() *Mysql

func (*Mysql) AutoIncrStr

func (db *Mysql) AutoIncrStr() string

func (*Mysql) BooleanStr

func (db *Mysql) BooleanStr(value bool) string

func (*Mysql) Quote

func (db *Mysql) Quote(name string) string

func (*Mysql) QuoteStr

func (db *Mysql) QuoteStr() string

func (*Mysql) SqlType

func (db *Mysql) SqlType(c *Column) string

func (*Mysql) SupportEngine

func (db *Mysql) SupportEngine() bool

func (*Mysql) TableCheckSql

func (db *Mysql) TableCheckSql(tableName string) (string, []interface{})

func (*Mysql) UpdateTableSql

func (db *Mysql) UpdateTableSql(tableName string, columns []*Column) string

type Postgres

type Postgres struct {
	BaseDialect
}

func NewPostgresDialect

func NewPostgresDialect() *Postgres

func (*Postgres) AutoIncrStr

func (db *Postgres) AutoIncrStr() string

func (*Postgres) BooleanStr

func (db *Postgres) BooleanStr(value bool) string

func (*Postgres) Default

func (b *Postgres) Default(col *Column) string

func (*Postgres) DropIndexSql

func (db *Postgres) DropIndexSql(tableName string, index *Index) string

func (*Postgres) LikeStr

func (b *Postgres) LikeStr() string

func (*Postgres) Quote

func (db *Postgres) Quote(name string) string

func (*Postgres) QuoteStr

func (db *Postgres) QuoteStr() string

func (*Postgres) SqlType

func (db *Postgres) SqlType(c *Column) string

func (*Postgres) SupportEngine

func (db *Postgres) SupportEngine() bool

func (*Postgres) TableCheckSql

func (db *Postgres) TableCheckSql(tableName string) (string, []interface{})

func (*Postgres) UpdateTableSql

func (db *Postgres) UpdateTableSql(tableName string, columns []*Column) string

type RawSqlMigration

type RawSqlMigration struct {
	MigrationBase
	// contains filtered or unexported fields
}

func (*RawSqlMigration) Mysql

func (m *RawSqlMigration) Mysql(sql string) *RawSqlMigration

func (*RawSqlMigration) Postgres

func (m *RawSqlMigration) Postgres(sql string) *RawSqlMigration

func (*RawSqlMigration) Sql

func (m *RawSqlMigration) Sql(dialect Dialect) string

func (*RawSqlMigration) Sqlite

func (m *RawSqlMigration) Sqlite(sql string) *RawSqlMigration

type RenameTableMigration

type RenameTableMigration struct {
	MigrationBase
	// contains filtered or unexported fields
}

func NewRenameTableMigration

func NewRenameTableMigration(oldName string, newName string) *RenameTableMigration

func (*RenameTableMigration) IfTableExists

func (m *RenameTableMigration) IfTableExists(tableName string) *RenameTableMigration

func (*RenameTableMigration) Rename

func (m *RenameTableMigration) Rename(oldName string, newName string) *RenameTableMigration

func (*RenameTableMigration) Sql

type SQLType

type SQLType string

type Sqlite3

type Sqlite3 struct {
	BaseDialect
}

func NewSqlite3Dialect

func NewSqlite3Dialect() *Sqlite3

func (*Sqlite3) AutoIncrStr

func (db *Sqlite3) AutoIncrStr() string

func (*Sqlite3) BooleanStr

func (db *Sqlite3) BooleanStr(value bool) string

func (*Sqlite3) DateTimeFunc

func (db *Sqlite3) DateTimeFunc(value string) string

func (*Sqlite3) DropIndexSql

func (db *Sqlite3) DropIndexSql(tableName string, index *Index) string

func (*Sqlite3) Quote

func (db *Sqlite3) Quote(name string) string

func (*Sqlite3) QuoteStr

func (db *Sqlite3) QuoteStr() string

func (*Sqlite3) SqlType

func (db *Sqlite3) SqlType(c *Column) string

func (*Sqlite3) SupportEngine

func (db *Sqlite3) SupportEngine() bool

func (*Sqlite3) TableCheckSql

func (db *Sqlite3) TableCheckSql(tableName string) (string, []interface{})

type Table

type Table struct {
	Name        string
	Columns     []*Column
	PrimaryKeys []string
	Indices     []*Index
}

type TableCharsetMigration

type TableCharsetMigration struct {
	MigrationBase
	// contains filtered or unexported fields
}

func NewTableCharsetMigration

func NewTableCharsetMigration(tableName string, columns []*Column) *TableCharsetMigration

func (*TableCharsetMigration) Sql

Jump to

Keyboard shortcuts

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