You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Роман Бородин 7743838258 Изменил(а) на 'README.md' 3 months ago
LICENSE Added LICENSE 3 years ago
README.md Изменил(а) на 'README.md' 3 months ago
go.mod Изменил(а) на 'go.mod' 3 months ago
go.sum first commit 3 years ago
template.go first commit 3 years ago

README.md

Templating for Migration Sources

migrate-template a wrapper for migration sources of library golang-migrate/migrate that allows the use of variables in migrations files.

Use in your Go project


import (
	template "github.com/mbk-lab/migrate-template"
	"github.com/golang-migrate/migrate/v4"
	"github.com/golang-migrate/migrate/v4/source"
)

func main() {
	sourceInstance, err := source.Open("file://migration")
	
	templateInstance := template.Wrap(
		sourceInstance,
		template.WithVars(template.M{
			"cluster": "cluster_name",
			"replicated_path": "/clickhouse/tables/db_name",
		}),
	)

	m, err := migrate.NewWithSourceInstance(
		"template", templateInstance,
		"clickhouse://...",
	)
	m.Steps(1)
}

Migration template using variables:


CREATE TABLE table_name ON CLUSTER {{.cluster}} (
	foo Int64,
	bar String
) ENGINE = ReplicatedReplacingMergeTree('{{.replicated_path}}.table_name', '{replica}')

Result:


CREATE TABLE table_name ON CLUSTER cluster_name (
	foo Int64,
	bar String
) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/db_name.table_name', '{replica}')