coremigrate

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package coremigrate holds implementation primitives shared by migratekit's Postgres migrator (the root package) and its ClickHouse migrator (migratekit/chmigrate): the migrations-tracking table DDL and environment template substitution. It is not part of migratekit's public API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdvisoryLockKey

func AdvisoryLockKey(s string) int64

AdvisoryLockKey derives a stable advisory-lock key from an arbitrary string.

func Contains

func Contains(slice []string, item string) bool

Contains reports whether item is present in slice.

func EnsurePublicMigrationsTable

func EnsurePublicMigrationsTable(ctx context.Context, db *sql.DB) error

EnsurePublicMigrationsTable creates/upgrades the tracker table. The tracker identity includes `schema` because WithSchema places tables in different schemas of the SAME database: without it, the same app applied to two schemas (e.g. doujins.* and hentai0.* sharing one DB) would record under one identity and the second schema would never get its tables. schema=” is the stamp for no-WithSchema groups only — Applied() matches schemas exactly, no wildcard.

func SubstituteTemplates

func SubstituteTemplates(sql string) (string, error)

SubstituteTemplates replaces template variables in SQL with environment variable values. Supports two template formats:

  • {{VAR_NAME}} (Handlebars/Mustache style)
  • ${VAR_NAME} (Shell/JS template literal style)

A referenced variable that is NOT SET in the environment is an error — a silent empty-string substitution would ship e.g. an empty password into DDL on a typo'd name. A variable explicitly set to the empty string is substituted as-is (assumed intentional).

Empty templates like ${} or {{}} are skipped (no substitution), and ON_CLUSTER placeholders are left intact for the ClickHouse driver to expand from its own Cluster config.

Types

type Tracker

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

Tracker records applied migrations and takes advisory locks in Postgres, for migrators whose target database is not Postgres itself (e.g. ClickHouse): the durable record and locking live in Postgres regardless of what's being migrated.

func NewTracker

func NewTracker(db *sql.DB) *Tracker

func (*Tracker) Applied

func (t *Tracker) Applied(ctx context.Context, app string, database string) ([]string, error)

func (*Tracker) Lock

func (t *Tracker) Lock(ctx context.Context, key int64) error

Lock acquires the advisory lock for key on a dedicated, pinned connection (session advisory locks belong to the connection that took them; going through the pool would acquire and release on different connections).

func (*Tracker) RecordApplied

func (t *Tracker) RecordApplied(ctx context.Context, app string, database string, name string) error

func (*Tracker) Setup

func (t *Tracker) Setup(ctx context.Context) error

func (*Tracker) Unlock

func (t *Tracker) Unlock(ctx context.Context, key int64) error

Unlock releases the advisory lock on the pinned connection, then closes it. Runs with a non-cancellable context; closing the connection releases the session lock even if pg_advisory_unlock fails.

Jump to

Keyboard shortcuts

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