migration

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package migration provides Goose-backed PostgreSQL schema migration helpers. Package migration 提供基于 Goose 的 PostgreSQL schema 迁移辅助函数。

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSchemaAhead reports that the database was migrated beyond the available sources.
	// ErrSchemaAhead 表示数据库版本高于当前可用的迁移源。
	ErrSchemaAhead = errors.New("database schema is newer than available migrations")
	// ErrSchemaBehind reports that migrations remain unapplied.
	// ErrSchemaBehind 表示仍有迁移尚未应用。
	ErrSchemaBehind = errors.New("database schema migrations are pending")
)

Functions

func RequireCurrent

func RequireCurrent(ctx context.Context, cfg Config) error

RequireCurrent requires the database to have no pending migrations and not exceed the available version. RequireCurrent 要求数据库没有待执行迁移,且版本不高于当前可用版本。

Types

type Config

type Config struct {
	DB           *sql.DB
	Migrations   fs.FS
	LockID       int64
	GoMigrations []*goose.Migration
}

Config configures Run and RequireCurrent. DB remains owned by the caller. A zero LockID uses Goose's default PostgreSQL advisory lock ID. Config 配置 Run 和 RequireCurrent。DB 的生命周期仍由调用方管理。 LockID 为零时使用 Goose 默认的 PostgreSQL advisory lock ID。

type Result

type Result struct {
	Total   int
	Applied int
	Skipped int
}

Result summarizes an upward migration run. Result 汇总一次向上迁移的执行结果。

func Run

func Run(ctx context.Context, cfg Config) (Result, error)

Run applies all pending migrations. It rejects a database newer than the available sources. Run 应用全部待执行迁移;数据库版本高于可用迁移源时拒绝执行。

Jump to

Keyboard shortcuts

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