sqlmigrate

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: MIT Imports: 12 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]"
)
View Source
const MULTI_SQL_SPLITPOINT = "---next"

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 {
	From          string
	To            string
	Dir           path.Local
	UpdateVersion func(db *sql.DB, dirnumber, filenumber int) error
	GetVersion    func(db *sql.DB) (dirnumber, filenumber int, err error)
}

type FS

type FS interface {
	fs.ReadOnly
	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 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(fsys fs.FS, dir_prefix string, prefix string) error

func (*MigrationManager) AddStructure

func (mm *MigrationManager) AddStructure(fsys fs.FS, dir_prefix string, prefix string) error

func (*MigrationManager) AddTest

func (mm *MigrationManager) AddTest(fsys fs.FS, dir_prefix string, prefix string) error

func (*MigrationManager) Down

func (mm *MigrationManager) Down(targetVersion int, verbose bool) error

func (*MigrationManager) Import

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

func (*MigrationManager) InitDir

func (mm *MigrationManager) InitDir(fsys fs.FS, logger io.Writer) 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 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)

Jump to

Keyboard shortcuts

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