Documentation ¶
Overview ¶
Package migrate mainly provides capacity to migrateBak and rollback database change automatically. keeping database structure is in consistency in team members.
Index ¶
- Variables
- type MigrationCollection
- func (m *MigrationCollection) CreateMigrateTable()
- func (m *MigrationCollection) MaxBatch() uint
- func (m *MigrationCollection) Refresh()
- func (m *MigrationCollection) Register(migrate Migrator)
- func (m *MigrationCollection) Rollback(step uint)
- func (m *MigrationCollection) SetConnection(db *gorm.DB)
- func (m *MigrationCollection) Upgrade()
- type MigrationModel
- type Migrator
Constants ¶
This section is empty.
Variables ¶
var DefaultMC = &MigrationCollection{}
DefaultMC In fact, is not available, unless you set the database connection by SetConnection method
Functions ¶
This section is empty.
Types ¶
type MigrationCollection ¶
type MigrationCollection struct {
// contains filtered or unexported fields
}
MigrationCollection is a collection of migrations
func (*MigrationCollection) CreateMigrateTable ¶
func (m *MigrationCollection) CreateMigrateTable()
CreateMigrateTable is used to create "migrations" table that includes all migration information.
func (*MigrationCollection) MaxBatch ¶
func (m *MigrationCollection) MaxBatch() uint
MaxBatch return the max batch number of migrations
func (*MigrationCollection) Refresh ¶
func (m *MigrationCollection) Refresh()
Refresh is used to refresh the whole database
func (*MigrationCollection) Register ¶
func (m *MigrationCollection) Register(migrate Migrator)
Register will add migration to collection
func (*MigrationCollection) Rollback ¶
func (m *MigrationCollection) Rollback(step uint)
Rollback will move back last migrating version, step represents the number of fallback versions.
func (*MigrationCollection) SetConnection ¶
func (m *MigrationCollection) SetConnection(db *gorm.DB)
SetConnection is used to set the db connection of database that will be operated on.
func (*MigrationCollection) Upgrade ¶
func (m *MigrationCollection) Upgrade()
Upgrade will apply new change to database, complete database structure upgrade.
type MigrationModel ¶
type MigrationModel struct { ID uint `gorm:"primary_key;AUTO_INCREMENT"` Migration string `gorm:"type:varchar(255);not null;UNIQUE_INDEX"` Batch uint `gorm:"type:int unsigned;not null"` }
MigrationModel is used to generate migrations table in database
func (MigrationModel) TableName ¶
func (m MigrationModel) TableName() string
TableName represent the name of migration table
Directories ¶
Path | Synopsis |
---|---|
Package migrations hold the migration file for operate database
|
Package migrations hold the migration file for operate database |