Documentation ¶
Index ¶
- Constants
- func Refresh() error
- func Register(name string, m Migrationer) error
- func Reset() error
- func Rollback(name string) error
- func Upgrade(lasttime int64) error
- type Column
- func (c *Column) Remove()
- func (c *Column) SetAuto(inc bool) *Column
- func (c *Column) SetDataType(dataType string) *Column
- func (c *Column) SetDefault(def string) *Column
- func (c *Column) SetNullable(null bool) *Column
- func (c *Column) SetPrimary(m *Migration) *Column
- func (c *Column) SetUnsigned(unsign bool) *Column
- type Foreign
- type Index
- type Migration
- func (m *Migration) AddColumns(columns ...*Column) *Migration
- func (m *Migration) AddForeign(foreign *Foreign) *Migration
- func (m *Migration) AddIndex(index *Index) *Migration
- func (m *Migration) AddPrimary(primary *Column) *Migration
- func (m *Migration) AddUnique(unique *Unique) *Migration
- func (m *Migration) AlterTable(tablename string)
- func (m *Migration) CreateTable(tablename, engine, charset string, p ...func())
- func (m *Migration) Down()
- func (m *Migration) Exec(name, status string) error
- func (m *Migration) ForeignCol(colname, foreigncol, foreigntable string) (foreign *Foreign)
- func (m *Migration) GetCreated() int64
- func (m *Migration) GetSQL() (sql string)
- func (m *Migration) Migrate(migrationType string)
- func (m *Migration) NewCol(name string) *Column
- func (m *Migration) PriCol(name string) *Column
- func (m *Migration) RenameColumn(from, to string) *RenameColumn
- func (m *Migration) Reset()
- func (m *Migration) SQL(sql string)
- func (m *Migration) UniCol(uni, name string) *Column
- func (m *Migration) Up()
- type Migrationer
- type RenameColumn
- type Unique
Constants ¶
const ( DateFormat = "20060102_150405" DBDateFormat = "2006-01-02 15:04:05" )
const the data format for the Bhojpur.NET Platform generate migration datatype
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(name string, m Migrationer) error
Register register the Migration in the map
Types ¶
type Column ¶
type Column struct { Name string Inc string Null string Default string Unsign string DataType string Modify bool // contains filtered or unexported fields }
Column struct defines a single column of a table
func (*Column) Remove ¶
func (c *Column) Remove()
Remove marks the columns to be removed. it allows reverse m to create the column.
func (*Column) SetDataType ¶
SetDataType sets the dataType of the column
func (*Column) SetDefault ¶
SetDefault sets the default value, prepend with "DEFAULT "
func (*Column) SetNullable ¶
SetNullable sets the column to be null
func (*Column) SetPrimary ¶
SetPrimary adds the columns to the primary key (can only be used any number of times in only one m)
func (*Column) SetUnsigned ¶
SetUnsigned sets the column to be unsigned int
type Foreign ¶
type Foreign struct { ForeignTable string ForeignColumn string OnDelete string OnUpdate string Column }
Foreign struct defines a single foreign relationship
func (*Foreign) SetOnDelete ¶
SetOnDelete sets the on delete of foreign
func (*Foreign) SetOnUpdate ¶
SetOnUpdate sets the on update of foreign
type Migration ¶
type Migration struct { Created string TableName string Engine string Charset string ModifyType string Columns []*Column Indexes []*Index Primary []*Column Uniques []*Unique Foreigns []*Foreign Renames []*RenameColumn RemoveColumns []*Column RemoveIndexes []*Index RemoveUniques []*Unique RemoveForeigns []*Foreign // contains filtered or unexported fields }
Migration defines the migrations by either SQL or DDL
func (*Migration) AddColumns ¶
AddColumns adds columns to m struct
func (*Migration) AddForeign ¶
AddForeign adds the column to foreign in m struct
func (*Migration) AddPrimary ¶
AddPrimary adds the column to primary in m struct
func (*Migration) AlterTable ¶
AlterTable set the ModifyType to alter
func (*Migration) CreateTable ¶
CreateTable creates the table on system
func (*Migration) Down ¶
func (m *Migration) Down()
Down implement in the Inheritance struct for down
func (*Migration) ForeignCol ¶
ForeignCol creates a new foreign column and returns the instance of column
func (*Migration) GetCreated ¶
GetCreated get the unixtime from the Created
func (*Migration) RenameColumn ¶
func (m *Migration) RenameColumn(from, to string) *RenameColumn
RenameColumn allows renaming of columns
type Migrationer ¶
type Migrationer interface { Up() Down() Reset() Exec(name, status string) error GetCreated() int64 }
Migrationer is an interface for all Migration struct
type RenameColumn ¶
type RenameColumn struct { OldName string OldNull string OldDefault string OldUnsign string OldDataType string NewName string Column }
RenameColumn struct allows renaming of columns
func (*RenameColumn) SetOldDataType ¶
func (c *RenameColumn) SetOldDataType(dataType string) *RenameColumn
SetOldDataType allows reverting to previous datatype on reverse ms
func (*RenameColumn) SetOldDefault ¶
func (c *RenameColumn) SetOldDefault(def string) *RenameColumn
SetOldDefault allows reverting to previous default on reverse ms
func (*RenameColumn) SetOldNullable ¶
func (c *RenameColumn) SetOldNullable(null bool) *RenameColumn
SetOldNullable allows reverting to previous nullable on reverse ms
func (*RenameColumn) SetOldUnsigned ¶
func (c *RenameColumn) SetOldUnsigned(unsign bool) *RenameColumn
SetOldUnsigned allows reverting to previous unsgined on reverse ms