migration

package
v1.7.8 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package migration is used for migration

The table structure is as follow:

CREATE TABLE `migrations` (
	`id_migration` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'surrogate key',
	`name` varchar(255) DEFAULT NULL COMMENT 'migration name, unique',
	`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'date migrated or rolled back',
	`statements` longtext COMMENT 'SQL statements for this migration',
	`rollback_statements` longtext,
	`status` enum('update','rollback') DEFAULT NULL COMMENT 'update indicates it is a normal migration while rollback means this migration is rolled back',
	PRIMARY KEY (`id_migration`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Index

Constants

View Source
const (
	DateFormat   = "20060102_150405"
	DBDateFormat = "2006-01-02 15:04:05"
)

const the data format for the bee generate migration datatype

Variables

This section is empty.

Functions

func Create added in v1.4.2

func Create(tbname string, columns ...Column) string

Create return create sql with the provided tbname and columns

func Drop added in v1.4.2

func Drop(tbname string, columns ...Column) string

Drop return the drop sql with the provided tbname and columns

func Refresh

func Refresh() error

Refresh first Reset, then Upgrade

func Register

func Register(name string, m Migrationer) error

Register register the Migration in the map

func Reset

func Reset() error

Reset reset all migration run all migration's down function

func Rollback

func Rollback(name string) error

Rollback rollback the migration by the name

func TableDDL added in v1.4.2

func TableDDL(tbname string, columns ...Column) string

TableDDL is still in think

func Upgrade

func Upgrade(lasttime int64) error

Upgrade upgrate the migration from lasttime

Types

type Column added in v1.4.2

type Column struct {
	Name    string
	Type    string
	Default interface{}
}

Column define the columns name type and Default

type Migration

type Migration struct {
	Created string
	// contains filtered or unexported fields
}

Migration the basic type which will implement the basic type

func (*Migration) Down

func (m *Migration) Down()

Down implement in the Inheritance struct for down

func (*Migration) Exec

func (m *Migration) Exec(name, status string) error

Exec execute the sql already add in the sql

func (*Migration) GetCreated

func (m *Migration) GetCreated() int64

GetCreated get the unixtime from the Created

func (*Migration) Reset

func (m *Migration) Reset()

Reset the sqls

func (*Migration) SQL added in v1.7.1

func (m *Migration) SQL(sql string)

SQL add sql want to execute

func (*Migration) Up

func (m *Migration) Up()

Up implement in the Inheritance struct for upgrade

type Migrationer

type Migrationer interface {
	Up()
	Down()
	Reset()
	Exec(name, status string) error
	GetCreated() int64
}

Migrationer is an interface for all Migration struct

type Table added in v1.4.2

type Table struct {
	TableName string
	Columns   []*Column
}

Table store the tablename and Column

func (*Table) Create added in v1.4.2

func (t *Table) Create() string

Create return the create sql

func (*Table) Drop added in v1.4.2

func (t *Table) Drop() string

Drop return the drop sql

Jump to

Keyboard shortcuts

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