pgmigrate

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pgmigrate 是配合 appkit.Migrator 选项的极简 schema 级迁移 runner。

每个 MigrationSet 对应一个域独占的 Postgres schema(DESIGN §8):runner 负责 建 schema、维护 {schema}.schema_migrations 历史表,并把 fs.FS 根下的 *.sql 按文件名升序应用。version 就是文件名。多副本并发启动安全:所有检查/应用都在 持有 pg_advisory_xact_lock(hashtext(schema)) 的事务内进行,同 schema 串行、 异 schema 互不阻塞。

迁移文件有两种形态:带 schema 限定名(单 schema 域),或全无前缀(分区域域, appkit new domain -partitioned)。无前缀文件在应用前 SET LOCAL search_path 到 set.Schema 落位——同一份文件可注册到多个分区 schema,见 applyFile。

已应用的迁移是不可变的:历史表记录内容的 sha256,启动时逐个比对, 改动已应用的文件会以 MIGRATION_DRIFT 拒绝启动(见 verifyChecksum)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Runner

func Runner(pool *pgxpool.Pool) func(ctx context.Context, sets []appkit.MigrationSet) error

Runner 返回可直接传给 appkit.Migrator 的迁移执行器。

对每个 MigrationSet:CREATE SCHEMA IF NOT EXISTS → 确保 schema_migrations 历史表 → 逐个应用未记录的 *.sql。每个文件在自己的事务里执行并记录版本: 坏 SQL 整体回滚,版本不会被记录,修复后重跑即可续上。

Types

This section is empty.

Jump to

Keyboard shortcuts

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