src

package
v0.0.0-...-a6bae08 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildMigrationMap

func BuildMigrationMap(db *sqlx.DB) (migrationsMap map[string]struct{}, err error)

func InitializeDB

func InitializeDB(ea EngineAdapter, c Connection) error

func InitializeMigrationTable

func InitializeMigrationTable(ea EngineAdapter, c Connection) (*sqlx.DB, error)

func ProcessFiles

func ProcessFiles(db *sqlx.DB, migrationsMap map[string]struct{}, migrationPath string) error

func ProcessMigration

func ProcessMigration(db *sqlx.DB, migrationPath, fileName string) error

func StartMigration

func StartMigration(c Connection) error

func ValidFile

func ValidFile(file fs.DirEntry) bool

Types

type Connection

type Connection struct {
	Engine         EngineType
	Host           string
	DB             string
	User           string
	Pwd            string
	AdminUser      string
	AdminPwd       string
	MigrationPath  string
	SkipInitialize bool
}

All the migration work is done here

type EngineAdapter

type EngineAdapter interface {
	ConnectDB(Connection, bool) (*sqlx.DB, error) // the second argument is to tell the function to use admin user/pwd and connect to root DB
	CheckUser(*sqlx.DB, Connection) error
	CheckDB(*sqlx.DB, Connection) error
	CheckTable(*sqlx.DB, Connection) error
	LockTable(*sqlx.DB) bool
	UnlockTable(*sqlx.DB) error
}

All the migration work is done here

func DetermineEnginerAdapter

func DetermineEnginerAdapter(et EngineType) EngineAdapter

type EngineType

type EngineType string

All the migration work is done here

const (
	POSTGRES EngineType = "postgres"
	MYSQL    EngineType = "mysql"
	SQLITE   EngineType = "sqlite"
)

type Migration

type Migration struct {
	Id       int    `db:"id"`
	FileName string `db:"file_name"`
}

All the migration work is done here

type Mock

type Mock struct{}

func (*Mock) CheckDB

func (m *Mock) CheckDB(db *sqlx.DB, c Connection) error

func (*Mock) CheckTable

func (m *Mock) CheckTable(db *sqlx.DB, c Connection) error

func (*Mock) CheckUser

func (m *Mock) CheckUser(db *sqlx.DB, c Connection) error

func (*Mock) ConnectDB

func (m *Mock) ConnectDB(c Connection, rootDB bool) (*sqlx.DB, error)

func (*Mock) LockTable

func (m *Mock) LockTable(db *sqlx.DB) bool

func (*Mock) UnlockTable

func (m *Mock) UnlockTable(db *sqlx.DB) error

type Mysql

type Mysql struct{}

func (*Mysql) CheckDB

func (m *Mysql) CheckDB(db *sqlx.DB, c Connection) error

func (*Mysql) CheckTable

func (m *Mysql) CheckTable(db *sqlx.DB, c Connection) error

func (*Mysql) CheckUser

func (m *Mysql) CheckUser(db *sqlx.DB, c Connection) error

func (*Mysql) ConnectDB

func (m *Mysql) ConnectDB(c Connection, rootDB bool) (*sqlx.DB, error)

func (*Mysql) LockTable

func (m *Mysql) LockTable(db *sqlx.DB) bool

func (*Mysql) UnlockTable

func (m *Mysql) UnlockTable(db *sqlx.DB) error

type Postgres

type Postgres struct{}

func (*Postgres) CheckDB

func (p *Postgres) CheckDB(db *sqlx.DB, c Connection) error

func (*Postgres) CheckTable

func (p *Postgres) CheckTable(db *sqlx.DB, c Connection) error

func (*Postgres) CheckUser

func (p *Postgres) CheckUser(db *sqlx.DB, c Connection) error

func (*Postgres) ConnectDB

func (p *Postgres) ConnectDB(c Connection, rootDB bool) (*sqlx.DB, error)

func (*Postgres) LockTable

func (p *Postgres) LockTable(db *sqlx.DB) bool

func (*Postgres) UnlockTable

func (p *Postgres) UnlockTable(db *sqlx.DB) error

type Sqlite

type Sqlite struct{}

func (*Sqlite) CheckDB

func (s *Sqlite) CheckDB(db *sqlx.DB, c Connection) error

func (*Sqlite) CheckTable

func (s *Sqlite) CheckTable(db *sqlx.DB, c Connection) error

func (*Sqlite) CheckUser

func (s *Sqlite) CheckUser(db *sqlx.DB, c Connection) error

func (*Sqlite) ConnectDB

func (s *Sqlite) ConnectDB(c Connection, rootDB bool) (*sqlx.DB, error)

func (*Sqlite) LockTable

func (s *Sqlite) LockTable(db *sqlx.DB) bool

the nature of sqlite is not to be distributed, no need to lock/unlock

func (*Sqlite) UnlockTable

func (s *Sqlite) UnlockTable(db *sqlx.DB) error

Jump to

Keyboard shortcuts

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