migrate

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MigrationMarker       = "-- [CHECK POINT] --"
	TimeFormat            = "2006-01-02 15:04:05"
	DefaultProgressSuffix = ".progress"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DBProgressStore

type DBProgressStore struct {
	// contains filtered or unexported fields
}

DBProgressStore 数据库进度存储

func NewDBProgressStore

func NewDBProgressStore(db *gorm.DB, scriptPath string) *DBProgressStore

NewDBProgressStore 创建数据库进度存储

func (*DBProgressStore) Load

func (s *DBProgressStore) Load() (int, error)

Load 从数据库加载上次迁移断点

func (*DBProgressStore) Save

func (s *DBProgressStore) Save(lineNum int) error

Save 保存当前迁移进度到数据库

type FileProgressStore

type FileProgressStore struct {
	// contains filtered or unexported fields
}

FileProgressStore 文件进度存储

func NewFileProgressStore

func NewFileProgressStore(path string) *FileProgressStore

NewFileProgressStore 创建文件进度存储

func (*FileProgressStore) Load

func (s *FileProgressStore) Load() (int, error)

Load 加载上次迁移断点

func (*FileProgressStore) Save

func (s *FileProgressStore) Save(lineNum int) error

Save 保存当前迁移进度

type FileScriptReader

type FileScriptReader struct {
	// contains filtered or unexported fields
}

FileScriptReader 文件脚本读取器

func NewFileScriptReader

func NewFileScriptReader(path string) *FileScriptReader

NewFileScriptReader 创建文件脚本读取器

func (*FileScriptReader) Read

func (r *FileScriptReader) Read() (string, error)

Read 读取脚本内容

type MigrationError

type MigrationError struct {
	Op  string
	Err error
}

MigrationError 自定义错误类型

func (*MigrationError) Error

func (e *MigrationError) Error() string

func (*MigrationError) Unwrap

func (e *MigrationError) Unwrap() error

type MigrationProgress

type MigrationProgress struct {
	ID         uint   `gorm:"primaryKey"`
	ScriptPath string `gorm:"index;size:255;not null"`
	LineNum    int    `gorm:"not null"`
	UpdatedAt  time.Time
}

MigrationProgress 迁移进度记录(数据库存储模型)

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

Migrator 数据库迁移器

func NewMigrator

func NewMigrator(db *gorm.DB, scriptPath string, opts ...MigratorOption) *Migrator

NewMigrator 创建一个新的数据库迁移器

func (*Migrator) Migrate

func (m *Migrator) Migrate(ctx context.Context) error

Migrate 执行迁移

type MigratorOption

type MigratorOption func(*Migrator)

MigratorOption 配置选项

func WithLogger

func WithLogger(l logger.Logger) MigratorOption

WithLogger 设置日志器

func WithProgressStore

func WithProgressStore(s ProgressStore) MigratorOption

WithProgressStore 设置进度存储

func WithScriptReader

func WithScriptReader(r ScriptReader) MigratorOption

WithScriptReader 设置脚本读取器

type ProgressStore

type ProgressStore interface {
	// Load 加载上次迁移断点
	Load() (int, error)
	// Save 保存当前迁移进度
	Save(lineNum int) error
}

ProgressStore 进度存储接口

type SQLStatement

type SQLStatement struct {
	LineNum int
	SQL     string
}

SQLStatement 表示一个待执行的 SQL 片段

type ScriptReader

type ScriptReader interface {
	// Read 读取脚本内容
	Read() (string, error)
}

ScriptReader SQL 脚本读取接口

Jump to

Keyboard shortcuts

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