migrate

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package migrate mainly provides capacity to migrateBak and rollback database change automatically. keeping database structure is in consistency in team members.

Index

Constants

This section is empty.

Variables

View Source
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

type Migrator

type Migrator interface {
	Name() string
	Up(db *gorm.DB) error
	Down(db *gorm.DB) error
}

Migrator is the interface that wraps Name, Up, Down Method.

Name method should return unique migration name in one database. Up method will be called in database upgrade. Down method will be called in database rollback.

Directories

Path Synopsis
Package migrations hold the migration file for operate database
Package migrations hold the migration file for operate database

Jump to

Keyboard shortcuts

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