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 ¶
- func ValidateMigrations(ctx context.Context, config *Config, fsys fs.FS) error
- type ClickHouse
- func (c *ClickHouse) Applied(ctx context.Context) ([]string, error)
- func (c *ClickHouse) ApplyMigrations(ctx context.Context, migrations []migratekit.Migration) (err error)
- func (c *ClickHouse) Close() error
- func (c *ClickHouse) Setup(ctx context.Context) error
- func (c *ClickHouse) ValidateAllApplied(ctx context.Context, migrations []migratekit.Migration) error
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateMigrations ¶
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) 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.