Documentation ¶
Overview ¶
Package sqltool contains logic to integrate existing tools like Flyway or Liquibase with the Atlas CLI.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // GolangMigrateFormatter returns migrate.Formatter compatible with golang-migrate/migrate. GolangMigrateFormatter = templateFormatter( "{{ now }}{{ with .Name }}_{{ . }}{{ end }}.up.sql", `{{ range .Changes }}{{ with .Comment }}-- {{ println . }}{{ end }}{{ printf "%s;\n" .Cmd }}{{ end }}`, "{{ now }}{{ with .Name }}_{{ . }}{{ end }}.down.sql", `{{ range $c := rev .Changes }}{{ with $stmts := .ReverseStmts }}{{ with $c.Comment }}-- reverse: {{ println . }}{{ end }}{{ range $stmts }}{{ printf "%s;\n" . }}{{ end }}{{ end }}{{ end }}`, ) // GooseFormatter returns migrate.Formatter compatible with pressly/goose. GooseFormatter = templateFormatter( "{{ now }}{{ with .Name }}_{{ . }}{{ end }}.sql", `-- +goose Up {{ range .Changes }}{{ with .Comment }}-- {{ println . }}{{ end }}{{ printf "%s;\n" .Cmd }}{{ end }} -- +goose Down {{ range $c := rev .Changes }}{{ with $stmts := .ReverseStmts }}{{ with $c.Comment }}-- reverse: {{ println . }}{{ end }}{{ range $stmts }}{{ printf "%s;\n" . }}{{ end }}{{ end }}{{ end }}`, ) // FlywayFormatter returns migrate.Formatter compatible with Flyway. FlywayFormatter = templateFormatter( "V{{ now }}{{ with .Name }}__{{ . }}{{ end }}.sql", `{{ range .Changes }}{{ with .Comment }}-- {{ println . }}{{ end }}{{ printf "%s;\n" .Cmd }}{{ end }}`, "U{{ now }}{{ with .Name }}__{{ . }}{{ end }}.sql", `{{ range $c := rev .Changes }}{{ with $stmts := .ReverseStmts }}{{ with $c.Comment }}-- reverse: {{ println . }}{{ end }}{{ range $stmts }}{{ printf "%s;\n" . }}{{ end }}{{ end }}{{ end }}`, ) // LiquibaseFormatter returns migrate.Formatter compatible with Liquibase. LiquibaseFormatter = templateFormatter( "{{ now }}{{ with .Name }}_{{ . }}{{ end }}.sql", `{{- $now := now -}} --liquibase formatted sql {{- range $index, $change := .Changes }} --changeset atlas:{{ $now }}-{{ inc $index }} {{ with $change.Comment }}--comment: {{ . }}{{ end }} {{ $change.Cmd }}; {{ with $stmts := .ReverseStmts }}{{ range $stmts }}{{ printf "--rollback: %s;\n" . }}{{ end }}{{ end }} {{- end }}`, ) // DBMateFormatter returns migrate.Formatter compatible with amacneil/dbmate. DBMateFormatter = templateFormatter( "{{ now }}{{ with .Name }}_{{ . }}{{ end }}.sql", `-- migrate:up {{ range .Changes }}{{ with .Comment }}-- {{ println . }}{{ end }}{{ printf "%s;\n" .Cmd }}{{ end }} -- migrate:down {{ range $c := rev .Changes }}{{ with $stmts := .ReverseStmts }}{{ with $c.Comment }}-- reverse: {{ println . }}{{ end }}{{ range $stmts }}{{ printf "%s;\n" . }}{{ end }}{{ end }}{{ end }}`, ) // DbmateFormatter is the same as DBMateFormatter. // Deprecated: Use DBMateFormatter instead. DbmateFormatter = DBMateFormatter )
Functions ¶
func SetRepeatableVersion ¶ added in v0.7.1
SetRepeatableVersion iterates over the migration files and assigns repeatable migrations a version number since Atlas does not have the concept of repeatable migrations. Each repeatable migration file gets assigned the version of the preceding migration file (or 0) followed by an 'R'.
Types ¶
type DBMateDir ¶ added in v0.6.1
DBMateDir wraps migrate.LocalDir and provides a migrate.Scanner implementation able to understand files generated by the DBMateFormatter for migration directory replaying.
func NewDBMateDir ¶ added in v0.6.1
NewDBMateDir returns a new DBMateDir.
type DBMateFile ¶ added in v0.6.1
DBMateFile wraps migrate.LocalFile with custom statements function.
func (*DBMateFile) StmtDecls ¶ added in v0.7.1
func (f *DBMateFile) StmtDecls() ([]*migrate.Stmt, error)
StmtDecls understands the migration format used by amacneil/dbmate sql migration files.
func (*DBMateFile) Stmts ¶ added in v0.6.1
func (f *DBMateFile) Stmts() ([]string, error)
Stmts understands the migration format used by amacneil/dbmate sql migration files.
type FlywayDir ¶ added in v0.6.1
FlywayDir wraps migrate.LocalDir and provides a migrate.Scanner implementation able to understand files generated by the FlywayFormatter for migration directory replaying.
func NewFlywayDir ¶ added in v0.6.1
NewFlywayDir returns a new FlywayDir.
type FlywayFile ¶ added in v0.6.1
FlywayFile wraps migrate.LocalFile with custom statements function.
func (FlywayFile) Desc ¶ added in v0.6.1
func (f FlywayFile) Desc() string
Desc implements File.Desc.
func (FlywayFile) Version ¶ added in v0.6.1
func (f FlywayFile) Version() string
Version implements File.Version.
type GolangMigrateDir ¶ added in v0.4.3
GolangMigrateDir wraps migrate.LocalDir and provides a migrate.Scanner implementation able to understand files generated by the GolangMigrateFormatter for migration directory replaying.
func NewGolangMigrateDir ¶ added in v0.4.3
func NewGolangMigrateDir(path string) (*GolangMigrateDir, error)
NewGolangMigrateDir returns a new GolangMigrateDir.
type GolangMigrateFile ¶ added in v0.6.0
GolangMigrateFile wraps migrate.LocalFile with custom description function.
func (*GolangMigrateFile) Desc ¶ added in v0.6.0
func (f *GolangMigrateFile) Desc() string
Desc implements File.Desc.
type GooseDir ¶ added in v0.6.1
GooseDir wraps migrate.LocalDir and provides a migrate.Scanner implementation able to understand files generated by the GooseFormatter for migration directory replaying.
func NewGooseDir ¶ added in v0.6.1
NewGooseDir returns a new GooseDir.
type GooseFile ¶ added in v0.6.1
GooseFile wraps migrate.LocalFile with custom statements function.
type LiquibaseDir ¶ added in v0.6.2
LiquibaseDir wraps migrate.LocalDir and provides a migrate.Scanner implementation able to understand files generated by the LiquibaseFormatter for migration directory replaying.
func NewLiquibaseDir ¶ added in v0.6.1
func NewLiquibaseDir(path string) (*LiquibaseDir, error)
NewLiquibaseDir returns a new LiquibaseDir.