migrator

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectDB

func ConnectDB(config *DBConfig, migrationsFS embed.FS) (*sql.DB, error)

func SetLogger

func SetLogger(l *zap.SugaredLogger)

Types

type CLI

type CLI struct {
	MigrateUp struct {
	} `cmd:"" help:"Apply database migrations"`
	MigrateDown struct {
		Max int `optional:"" help:"Max number of migrations to unapply" default:"0"`
	} `cmd:"" help:"Unapply database migrations"`
}

type DBConfig

type DBConfig struct {
	// contains filtered or unexported fields
}

func DefaultDBConfig

func DefaultDBConfig() *DBConfig

func (*DBConfig) AppName

func (c *DBConfig) AppName(appName string) *DBConfig

func (*DBConfig) ConnOpts

func (c *DBConfig) ConnOpts(connOpts string) *DBConfig

func (*DBConfig) DSN

func (c *DBConfig) DSN(dsn string) *DBConfig

func (*DBConfig) GetFullDSN

func (c *DBConfig) GetFullDSN() string

func (*DBConfig) Name

func (c *DBConfig) Name(dbName string) *DBConfig

func (*DBConfig) NoMigration

func (c *DBConfig) NoMigration() *DBConfig

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

func NewMigrator

func NewMigrator(db *sql.DB, fs embed.FS, migrTableName string) Migrator

func (Migrator) CreateDB

func (m Migrator) CreateDB(dbName string) error

CreateDB creates the requested database.

func (Migrator) DropDB

func (m Migrator) DropDB(dbName string) error

DropDB drops the requested database.

func (Migrator) MigrateDown

func (m Migrator) MigrateDown(max int) (int, error)

MigrateDown undoes a specified number of migrations.

func (Migrator) MigrateUp

func (m Migrator) MigrateUp() (int, error)

MigrateUp executes forward migrations.

func (Migrator) Truncate

func (m Migrator) Truncate(tables []string) error

Truncate purges records from the requested tables.

type TestDBCleanup

type TestDBCleanup func() error

func CreateTestDB

func CreateTestDB(mfs embed.FS) (*sql.DB, TestDBCleanup, error)

Jump to

Keyboard shortcuts

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