template

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 5 Imported by: 0

README

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/FindMyKids/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}')

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

func Wrap(inner source.Driver, opts ...Option) source.Driver

Types

type M

type M map[string]interface{}

type Option

type Option func(d *driver)

func WithFuncs

func WithFuncs(funcs template.FuncMap) Option

func WithVars

func WithVars(vars M) Option

Jump to

Keyboard shortcuts

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