sqltool

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

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

View Source
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

func SetRepeatableVersion(ff []migrate.File)

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

type DBMateDir struct{ *migrate.LocalDir }

DBMateDir wraps migrate.LocalDir and provides a migrate.Scanner implementation able to understand files generated by the DBMateFormatter for migration directory replaying.

func NewDBMateDir

func NewDBMateDir(path string) (*DBMateDir, error)

NewDBMateDir returns a new DBMateDir.

func (*DBMateDir) Files

func (d *DBMateDir) Files() ([]migrate.File, error)

Files looks for all files with up.sql suffix and orders them by filename.

type DBMateFile

type DBMateFile struct{ *migrate.LocalFile }

DBMateFile wraps migrate.LocalFile with custom statements function.

func (*DBMateFile) StmtDecls

func (f *DBMateFile) StmtDecls() ([]*migrate.Stmt, error)

StmtDecls understands the migration format used by amacneil/dbmate sql migration files.

func (*DBMateFile) Stmts

func (f *DBMateFile) Stmts() ([]string, error)

Stmts understands the migration format used by amacneil/dbmate sql migration files.

type FlywayDir

type FlywayDir struct{ fs.FS }

FlywayDir wraps fs.FS and provides a migrate.Scanner implementation able to understand files generated by the FlywayFormatter for migration directory replaying.

func NewFlywayDir

func NewFlywayDir(path string) (*FlywayDir, error)

NewFlywayDir returns a new FlywayDir.

func (*FlywayDir) Checksum

func (d *FlywayDir) Checksum() (migrate.HashFile, error)

Checksum implements Dir.Checksum. By default, it calls Files() and creates a checksum from them.

func (*FlywayDir) Files

func (d *FlywayDir) Files() ([]migrate.File, error)

Files implements Scanner.Files. It looks for all files with .sql suffix. The given directory is recursively scanned for non-hidden subdirectories. All found files will be ordered by migration type (Baseline, Versioned, Repeatable) and filename.

func (*FlywayDir) Path

func (d *FlywayDir) Path() string

Path returns the local path used for opening this dir.

func (*FlywayDir) WriteFile

func (d *FlywayDir) WriteFile(name string, b []byte) error

WriteFile implements Dir.WriteFile.

type FlywayFile

type FlywayFile struct{ *migrate.LocalFile }

FlywayFile wraps migrate.LocalFile with custom statements function.

func (FlywayFile) Desc

func (f FlywayFile) Desc() string

Desc implements File.Desc.

func (FlywayFile) Version

func (f FlywayFile) Version() string

Version implements File.Version.

type GolangMigrateDir

type GolangMigrateDir struct{ fs.FS }

GolangMigrateDir wraps fs.FS and provides a migrate.Scanner implementation able to understand files generated by the GolangMigrateFormatter for migration directory replaying.

func NewGolangMigrateDir

func NewGolangMigrateDir(path string) (*GolangMigrateDir, error)

NewGolangMigrateDir returns a new GolangMigrateDir.

func (*GolangMigrateDir) Checksum

func (d *GolangMigrateDir) Checksum() (migrate.HashFile, error)

Checksum implements Dir.Checksum. By default, it calls Files() and creates a checksum from them.

func (*GolangMigrateDir) Files

func (d *GolangMigrateDir) Files() ([]migrate.File, error)

Files implements Scanner.Files. It looks for all files with up.sql suffix and orders them by filename.

func (*GolangMigrateDir) Path

func (d *GolangMigrateDir) Path() string

Path returns the local path used for opening this dir.

func (*GolangMigrateDir) WriteFile

func (d *GolangMigrateDir) WriteFile(name string, b []byte) error

WriteFile implements Dir.WriteFile.

type GolangMigrateFile

type GolangMigrateFile struct{ *migrate.LocalFile }

GolangMigrateFile wraps migrate.LocalFile with custom description function.

func (*GolangMigrateFile) Desc

func (f *GolangMigrateFile) Desc() string

Desc implements File.Desc.

type GooseDir

type GooseDir struct{ *migrate.LocalDir }

GooseDir wraps migrate.LocalDir and provides a migrate.Scanner implementation able to understand files generated by the GooseFormatter for migration directory replaying.

func NewGooseDir

func NewGooseDir(path string) (*GooseDir, error)

NewGooseDir returns a new GooseDir.

func (*GooseDir) Files

func (d *GooseDir) Files() ([]migrate.File, error)

Files looks for all files with .sql suffix and orders them by filename.

type GooseFile

type GooseFile struct{ *migrate.LocalFile }

GooseFile wraps migrate.LocalFile with custom statements function.

func (*GooseFile) StmtDecls

func (f *GooseFile) StmtDecls() ([]*migrate.Stmt, error)

StmtDecls understands the migration format used by pressly/goose sql migration files.

func (*GooseFile) Stmts

func (f *GooseFile) Stmts() ([]string, error)

Stmts understands the migration format used by pressly/goose sql migration files.

type LiquibaseDir

type LiquibaseDir struct{ *migrate.LocalDir }

LiquibaseDir wraps migrate.LocalDir and provides a migrate.Scanner implementation able to understand files generated by the LiquibaseFormatter for migration directory replaying.

func NewLiquibaseDir

func NewLiquibaseDir(path string) (*LiquibaseDir, error)

NewLiquibaseDir returns a new LiquibaseDir.

Jump to

Keyboard shortcuts

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