Documentation ¶
Index ¶
- Constants
- Variables
- func CheckFileExist(filename string) (exists bool)
- func Output(slice interface{}, grid Grid)
- func StringLength(r []rune) int
- func WriteFile(filename, content string) (n int, err error)
- type Config
- type Grid
- type Migrate
- func (m Migrate) Create(filename string) (err error)
- func (m Migrate) ExecDown(filename string) (err error)
- func (m Migrate) ExecUp() (err error)
- func (m Migrate) FindMigrations() ([]*Migration, error)
- func (m Migrate) GetExecutedMigrations() (migrations []MigrationModel, err error)
- func (m Migrate) InitMigrationTable() (err error)
- func (m Migrate) Status() (err error)
- type Migration
- type MigrationModel
- type MigrationOutput
- type ParsedMigration
Constants ¶
View Source
const ( MigrationUp uint8 = 1 MigrationDown uint8 = 2 )
迁移操作
Variables ¶
View Source
var ( // LineSeparator can be used to split migrations by an exact line match. This line // will be removed from the output. If left blank, it is not considered. It is defaulted // to blank so you will have to set it manually. // Use case: in MSSQL, it is convenient to separate commands by GO statements like in // SQL Query Analyzer. LineSeparator = "" )
Functions ¶
Types ¶
type Config ¶
type Config struct { Dir string // migrate迁移文件的路径,相对路径<相对main入口|编译后二进制文件> Fs *embed.FS // `Dir`参数指向的路径里的embed机制形成的fs.FS变量,以实现build编译嵌入embed迁移文件 TableName string // 记录migrate迁移历史的数据库表名 DB *sql.DB // 数据库驱动句柄,用于操纵数据库 }
Config 配置
type Grid ¶
type Grid string
Grid Grid
const GridASCII Grid = "ascii"
GridASCII ascii格式表格
const GridBoxDrawing Grid = "box-drawing"
GridBoxDrawing box-drawing格式表格
type Migrate ¶
type Migrate struct {
// contains filtered or unexported fields
}
Migrate Migrate对象
func (Migrate) FindMigrations ¶
FindMigrations 从本地文件系统|fs.FS读取全部迁移文件
func (Migrate) GetExecutedMigrations ¶
func (m Migrate) GetExecutedMigrations() (migrations []MigrationModel, err error)
GetExecutedMigrations 从Db获取已执行的迁移记录
func (Migrate) InitMigrationTable ¶
InitMigrationTable 初始化数据迁移表
type Migration ¶
type Migration struct { Id string Up []string Down []string DisableTransactionUp bool DisableTransactionDown bool }
Migration 解析后的迁移文件数据结构
func (Migration) NumberPrefixMatches ¶
NumberPrefixMatches 匹配数字版本号
type MigrationModel ¶
type MigrationModel struct { ID uint64 `json:"id"` Migration string `json:"migration"` CreatedAt time.Time `json:"created_at"` }
MigrationModel MigrationModel
type MigrationOutput ¶
MigrationOutput 列表输出
type ParsedMigration ¶
type ParsedMigration struct { UpStatements []string DownStatements []string DisableTransactionUp bool DisableTransactionDown bool }
func ParseMigration ¶
func ParseMigration(r io.ReadSeeker) (*ParsedMigration, error)
ParseMigration Split the given sql script into individual statements.
The base case is to simply split on semicolons, as these naturally terminate a statement.
However, more complex cases like pl/pgsql can have semicolons within a statement. For these cases, we provide the explicit annotations 'StatementBegin' and 'StatementEnd' to allow the script to tell us to ignore semicolons.
Click to show internal directories.
Click to hide internal directories.