chmigrate

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: 13 Imported by: 0

Documentation

Overview

Package chmigrate is migratekit's ClickHouse migration driver. It lives in its own package (and imports github.com/ClickHouse/clickhouse-go/v2) so that consumers who only need migratekit's Postgres migrator never pull in the ClickHouse client: Go's module graph pruning drops clickhouse-go/ch-go from a consumer's build list once nothing in that consumer imports this package.

See the root package's README for the full migration-file/template-variable contract; this package covers only what's specific to ClickHouse.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateMigrations

func ValidateMigrations(ctx context.Context, config *Config, fsys fs.FS) error

ValidateMigrations validates that every migration in fsys has been applied for the app named in config. Read-only startup gate: never creates tables. Mirrors migratekit.ValidatePostgresMigrations for the ClickHouse driver.

Types

type ClickHouse

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

ClickHouse handles ClickHouse migrations via native protocol.

func New

func New(config *Config) *ClickHouse

New creates a ClickHouse migrator from config. Uses native protocol for all connections.

func (*ClickHouse) Applied

func (c *ClickHouse) Applied(ctx context.Context) ([]string, error)

Applied returns list of applied migrations

func (*ClickHouse) ApplyMigrations

func (c *ClickHouse) ApplyMigrations(ctx context.Context, migrations []migratekit.Migration) (err error)

ApplyMigrations applies all unapplied migrations (only locks if needed) Automatically calls Setup() to ensure migration tables exist before proceeding.

func (*ClickHouse) Close

func (c *ClickHouse) Close() error

Close closes the connection

func (*ClickHouse) Setup

func (c *ClickHouse) Setup(ctx context.Context) error

Setup ensures database and tables exist

func (*ClickHouse) ValidateAllApplied

func (c *ClickHouse) ValidateAllApplied(ctx context.Context, migrations []migratekit.Migration) error

ValidateAllApplied checks if all provided migrations have been applied. Returns an error listing any pending migrations if validation fails. This is intended for use during application startup to ensure the database schema is up-to-date before the app starts serving requests.

type Config

type Config struct {
	ClientAddr string // Native protocol address (e.g., clickhouse:9000)
	Database   string
	Username   string
	Password   string
	App        string
	Cluster    string // Optional; if specified, uses ON CLUSTER for DDL statements

	// Required. ClickHouse migration tracking + locking is done in Postgres:
	// - tracking: Postgres public.migrations with database='clickhouse'
	// - locking: Postgres advisory locks
	//
	// This intentionally avoids ClickHouse-based migration tables (`migrations`, `migration_locks`)
	// which are awkward to restore/merge and are not a good fit for authoritative state.
	PostgresDB *sql.DB
}

Config holds configuration for ClickHouse migrations.

Jump to

Keyboard shortcuts

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