Documentation
¶
Overview ¶
Package migration provides Goose-backed PostgreSQL schema migration helpers. Package migration 提供基于 Goose 的 PostgreSQL schema 迁移辅助函数。
Index ¶
Constants ¶
This section is empty.
Variables ¶
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") // ErrTargetInvalid reports that a RunTo target is outside the upward migration range. // ErrTargetInvalid 表示 RunTo 的目标超出向上迁移范围。 ErrTargetInvalid = errors.New("invalid migration target") )
Functions ¶
Types ¶
type Config ¶
Config configures Run, RunTo, and RequireCurrent. DB remains owned by the caller. A zero LockID uses Goose's default PostgreSQL advisory lock ID. Config 配置 Run、RunTo 和 RequireCurrent。DB 的生命周期仍由调用方管理。 LockID 为零时使用 Goose 默认的 PostgreSQL advisory lock ID。
type Result ¶
Result summarizes a successful upward migration run. RunTo excludes sources newer than its target from Total and Skipped. Result 汇总一次成功的向上迁移执行结果。 RunTo 的 Total 和 Skipped 不包含高于目标版本的迁移源。
func Run ¶
Run applies all pending migrations. It rejects a database newer than the available sources. Run 应用全部待执行迁移;数据库版本高于可用迁移源时拒绝执行。
func RunTo ¶ added in v0.2.8
RunTo applies pending migrations through target. The target cannot be older than the database or newer than the available migrations. RunTo is intended for upgrade tests and maintenance, not normal application startup. RunTo 应用截至 target 的待执行迁移。 目标不能低于数据库版本,也不能高于当前可用迁移。 RunTo 用于升级测试和维护,不用于正常应用启动。