Documentation
¶
Overview ¶
Package headgatemigrate provides versioned, embedded schema migrations for headgate's Postgres and MySQL stores.
Historical migration checksums are immutable. Postgres applies each version and its history row transactionally. MySQL DDL auto-commits, so each statement is resumable, a connection-scoped lock serializes callers, and history is recorded only after the resulting schema passes the current manifest.
Index ¶
- Constants
- Variables
- func AppliedMySQL(ctx context.Context, db *sql.DB) (InstallationState, []AppliedMigration, error)
- func AppliedPostgres(ctx context.Context, conn *pgx.Conn) (InstallationState, []AppliedMigration, error)
- func AppliedPostgresInSchema(ctx context.Context, conn *pgx.Conn, schema string) (InstallationState, []AppliedMigration, error)
- func Checksum(migration Migration) string
- func LatestVersion(backend Backend) int
- func MySQLMigrationLockName(namespace, database string) (string, error)
- func ValidateHistory(backend Backend, applied []AppliedMigration) error
- type AppliedMigration
- func AdoptMySQL(ctx context.Context, db *sql.DB) ([]AppliedMigration, error)
- func AdoptMySQLWithLockNamespace(ctx context.Context, db *sql.DB, lockNamespace string) ([]AppliedMigration, error)
- func AdoptPostgres(ctx context.Context, conn *pgx.Conn) ([]AppliedMigration, error)
- func AdoptPostgresInSchema(ctx context.Context, conn *pgx.Conn, schema string) ([]AppliedMigration, error)
- type Backend
- type Direction
- type HistoryError
- type InstallationState
- type Migration
- type MySQLValidation
- type Options
- type PostgresValidation
- type Result
- func MigrateMySQL(ctx context.Context, db *sql.DB, direction Direction, options Options) (Result, error)
- func MigrateMySQLWithLockNamespace(ctx context.Context, db *sql.DB, direction Direction, options Options, ...) (Result, error)
- func MigratePostgres(ctx context.Context, conn *pgx.Conn, direction Direction, options Options) (Result, error)
- func MigratePostgresInSchema(ctx context.Context, conn *pgx.Conn, schema string, direction Direction, ...) (Result, error)
- type SchemaError
- type Step
Constants ¶
const DefaultMySQLLockNamespace = "headgate"
DefaultMySQLLockNamespace preserves the lock name used before namespaces were configurable: headgate:migrate:<database>.
Variables ¶
var ErrUnversionedSchema = errors.New("headgate tables exist without migration history; validate and adopt the current schema before migrating")
Functions ¶
func AppliedMySQL ¶
func AppliedMySQL(ctx context.Context, db *sql.DB) (InstallationState, []AppliedMigration, error)
func AppliedPostgres ¶
func AppliedPostgres(ctx context.Context, conn *pgx.Conn) (InstallationState, []AppliedMigration, error)
func AppliedPostgresInSchema ¶
func AppliedPostgresInSchema( ctx context.Context, conn *pgx.Conn, schema string, ) (InstallationState, []AppliedMigration, error)
func LatestVersion ¶
func MySQLMigrationLockName ¶
MySQLMigrationLockName builds the connection-scoped migration lock key. Readable names stay backward-compatible; only an overlong database is hashed under a distinct :h: marker to fit MySQL's 64-byte GET_LOCK limit without aliasing a short literal database name.
func ValidateHistory ¶
func ValidateHistory(backend Backend, applied []AppliedMigration) error
Types ¶
type AppliedMigration ¶
func AdoptMySQL ¶
func AdoptPostgres ¶
func AdoptPostgresInSchema ¶
type HistoryError ¶
type HistoryError struct{ Message string }
func (*HistoryError) Error ¶
func (e *HistoryError) Error() string
type InstallationState ¶
type InstallationState string
const ( Empty InstallationState = "empty" Unversioned InstallationState = "unversioned" Versioned InstallationState = "versioned" )
type Migration ¶
func Migrations ¶
type MySQLValidation ¶
type MySQLValidation struct {
State InstallationState
CurrentVersion int
LatestVersion int
Applied []AppliedMigration
Messages []string
}
func ValidateMySQL ¶
func (MySQLValidation) OK ¶
func (v MySQLValidation) OK() bool
type PostgresValidation ¶
type PostgresValidation struct {
State InstallationState
CurrentVersion int
LatestVersion int
Applied []AppliedMigration
Messages []string
}
func ValidatePostgres ¶
func (PostgresValidation) OK ¶
func (v PostgresValidation) OK() bool
type SchemaError ¶
type SchemaError struct{ Messages []string }
func (*SchemaError) Error ¶
func (e *SchemaError) Error() string