sqlmigrate

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 10 Imported by: 0

README

sqlmigrate

sqlmigrate helps with database migrations. it can also deal with importing migrations from one to another database (within the same connection).

Docs

https://pkg.go.dev/gitlab.com/golang-utils/sqlmigrate

Documentation

Index

Constants

View Source
const (
	PlaceholderSchema       = "[schema]"
	PlaceholderSrcSchema    = "[src_schema]"
	PlaceholderTargetSchema = "[target_schema]"
)

Variables

View Source
var (
	StructureDir = path.Relative("structure/")
	ImportDir    = path.Relative("imports/")
	TestsDir     = path.Relative("tests/")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string
	Port     string
	User     string
	Password string
	From     string
	To       string
	Dir      path.Local
}

type FS

type FS interface {
	fs.FS
	fs.ExtGlob
}

type Import

type Import struct {
	ImportSQL string
	TestSQL   string
	ClearSQL  string
	// contains filtered or unexported fields
}

func (Import) Exec

func (m Import) Exec(db *sql.DB, sql string) error

func (Import) Path

func (m Import) Path(rootDir path.Relative, suffix string) path.Relative

func (Import) PathClear

func (m Import) PathClear() path.Relative

func (Import) PathImport

func (m Import) PathImport() path.Relative

func (Import) PathTest

func (m Import) PathTest() path.Relative

func (Import) QueryRow

func (m Import) QueryRow(db *sql.DB, sql string) *sql.Row

func (Import) ReadSQL

func (m Import) ReadSQL(fsys FS, rootDir path.Relative, target *string, suffix string) error

func (Import) RunClear

func (m Import) RunClear(db *sql.DB, srcdbname, targetdbname string) error

func (Import) RunImport

func (m Import) RunImport(db *sql.DB, srcdbname, targetdbname string) error

func (Import) RunTest

func (m Import) RunTest(db *sql.DB, srcdbname, targetdbname string) error

func (*Import) Scan

func (m *Import) Scan(fsys FS, mt path.Relative) (err error)

type Imports

type Imports []Import

func (Imports) CheckForDuplicates

func (m Imports) CheckForDuplicates() error

func (Imports) Len

func (m Imports) Len() int

func (Imports) Less

func (m Imports) Less(a, b int) bool

func (Imports) Swap

func (m Imports) Swap(a, b int)

type Migration

type Migration struct {
	UpSQL   string
	DownSQL string
	TestSQL string
	// contains filtered or unexported fields
}

func (Migration) Exec

func (m Migration) Exec(db *sql.DB, sql string) error

func (Migration) Path

func (m Migration) Path(rootDir path.Relative, suffix string) path.Relative

func (Migration) PathDown

func (m Migration) PathDown() path.Relative

func (Migration) PathTest

func (m Migration) PathTest() path.Relative

func (Migration) PathUp

func (m Migration) PathUp() path.Relative

func (Migration) QueryRow

func (m Migration) QueryRow(db *sql.DB, sql string) *sql.Row

func (Migration) ReadSQL

func (m Migration) ReadSQL(fsys FS, rootDir path.Relative, target *string, suffix string) error

func (Migration) RunDown

func (m Migration) RunDown(db *sql.DB, dbname string) error

func (Migration) RunTest

func (m Migration) RunTest(db *sql.DB, dbname string) error

func (Migration) RunUp

func (m Migration) RunUp(db *sql.DB, dbname string) error

func (*Migration) Scan

func (m *Migration) Scan(fsys FS, mt path.Relative) (err error)

type MigrationManager

type MigrationManager struct {
	Config
	// contains filtered or unexported fields
}

func New

func New(db *sql.DB, conf Config) *MigrationManager

func NewFS

func NewFS(db *sql.DB, fsys FS, conf Config) *MigrationManager

func (*MigrationManager) AddImport

func (mm *MigrationManager) AddImport() error

func (*MigrationManager) AddStructure

func (mm *MigrationManager) AddStructure() error

func (*MigrationManager) AddTest

func (mm *MigrationManager) AddTest() error

func (*MigrationManager) Down

func (mm *MigrationManager) Down(verbose bool) error

func (*MigrationManager) Import

func (mm *MigrationManager) Import(verbose bool) error

func (*MigrationManager) InitDir

func (mm *MigrationManager) InitDir(logger io.Writer) error

func (*MigrationManager) PrepareImport

func (mm *MigrationManager) PrepareImport(verbose bool) error

func (*MigrationManager) Rebuild

func (mm *MigrationManager) Rebuild(verbose bool) error

func (*MigrationManager) Run

func (mm *MigrationManager) Run(verbose bool) error

func (*MigrationManager) Test

func (mm *MigrationManager) Test(verbose bool) error

func (*MigrationManager) Up

func (mm *MigrationManager) Up(verbose bool) error

type Migrations

type Migrations []Migration

func (Migrations) CheckForDuplicates

func (m Migrations) CheckForDuplicates() error

func (Migrations) Len

func (m Migrations) Len() int

func (Migrations) Less

func (m Migrations) Less(a, b int) bool

func (Migrations) Swap

func (m Migrations) Swap(a, b int)

type Tester

type Tester struct {
	SrcSQL    string
	TargetSQL string
	// contains filtered or unexported fields
}

func (Tester) Exec

func (m Tester) Exec(db *sql.DB, sql string) error

func (Tester) Path

func (m Tester) Path(rootDir path.Relative, suffix string) path.Relative

func (Tester) PathSrc

func (m Tester) PathSrc() path.Relative

func (Tester) PathTarget

func (m Tester) PathTarget() path.Relative

func (Tester) QueryRow

func (m Tester) QueryRow(db *sql.DB, sql string) *sql.Row

func (Tester) ReadSQL

func (m Tester) ReadSQL(fsys FS, rootDir path.Relative, target *string, suffix string) error

func (Tester) Run

func (m Tester) Run(db *sql.DB, srcDB, targetDB string) error

func (Tester) RunSrc

func (m Tester) RunSrc(db *sql.DB, dbname string) (string, error)

func (Tester) RunTarget

func (m Tester) RunTarget(db *sql.DB, dbname string) (string, error)

func (*Tester) Scan

func (m *Tester) Scan(fsys FS, mt path.Relative) (err error)

type Testers

type Testers []Tester

func (Testers) CheckForDuplicates

func (m Testers) CheckForDuplicates() error

func (Testers) Len

func (m Testers) Len() int

func (Testers) Less

func (m Testers) Less(a, b int) bool

func (Testers) Swap

func (m Testers) Swap(a, b int)

Jump to

Keyboard shortcuts

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