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 ¶
- func AdvisoryLockKey(s string) int64
- func Contains(slice []string, item string) bool
- func EnsurePublicMigrationsTable(ctx context.Context, db *sql.DB) error
- func SubstituteTemplates(sql string) (string, error)
- type Tracker
- func (t *Tracker) Applied(ctx context.Context, app string, database string) ([]string, error)
- func (t *Tracker) Lock(ctx context.Context, key int64) error
- func (t *Tracker) RecordApplied(ctx context.Context, app string, database string, name string) error
- func (t *Tracker) Setup(ctx context.Context) error
- func (t *Tracker) Unlock(ctx context.Context, key int64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdvisoryLockKey ¶
AdvisoryLockKey derives a stable advisory-lock key from an arbitrary string.
func EnsurePublicMigrationsTable ¶
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 ¶
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 (*Tracker) Lock ¶
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).