sqlmigrator

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_LOG_FILE = ".commit-status"
)

Variables

View Source
var (
	ErrInvalidMigration = errors.New("invalid migration")
)

Functions

func CreateFile

func CreateFile(filePath, content string) error

func InitializeMigrationsFolder

func InitializeMigrationsFolder(ctx *Context) error

func NewMigrator

func NewMigrator(dbRepo DBRepo) *migrator

func ReadLines

func ReadLines(filePath string) ([]string, error)

func SelectExtention

func SelectExtention(database Database) string

func SelectSubDirectory

func SelectSubDirectory(database Database) string

Types

type Context

type Context struct {
	WorkDir    string
	LogFile    string
	Database   Database
	DryRun     bool
	Migrations Migrations
}

func NewContext

func NewContext(workDir string, dbType Database, logFile string, dry bool) *Context

func (*Context) LoadMigrationEntries

func (ctx *Context) LoadMigrationEntries() error

func (*Context) WriteMigrationEntries

func (ctx *Context) WriteMigrationEntries() error

type DBRepo

type DBRepo interface {
	Exec(query string) error
	PushHistory(migration *MigrationDBEntry) error
	LoadHistory() ([]*MigrationDBEntry, error)
	InitMigrationTable() error
	DeleteMigrationTable() error
}

type Database

type Database string
const (
	PostgresDB Database = "postgres"
	MySQLDB    Database = "mysql"
	SQLiteDB   Database = "sqlite"
)

func DefaultContextConfig

func DefaultContextConfig() (string, Database, string)

func SelectDatabase

func SelectDatabase(database string) Database

type Generator

type Generator struct {
	Name          string
	NumToGenerate int
	DryRun        bool
	Fill          bool
}

func NewGenerator

func NewGenerator(name string, numToGenerate int, fill bool) *Generator

func (*Generator) Clean

func (g *Generator) Clean(ctx *Context) ([]string, error)

func (*Generator) Generate

func (g *Generator) Generate(ctx *Context) ([]string, error)

type MigrationDBEntry

type MigrationDBEntry struct {
	Number    int
	Name      string
	Direction string
	Created   time.Time
}

type MigrationFileEntry

type MigrationFileEntry struct {
	Number       int
	Name         string
	Committed    bool
	UpFilePath   string
	DownFilePath string
}

func GenerateNextMigrations

func GenerateNextMigrations(lastMigrationNumber int, name string, numToGenerate int) []*MigrationFileEntry

func LastMigration

func LastMigration(ctx *Context) *MigrationFileEntry

func LoadAppliedMigrations added in v1.2.2

func LoadAppliedMigrations(ctx *Context) []*MigrationFileEntry

func LoadUnappliedMigrations added in v1.2.2

func LoadUnappliedMigrations(ctx *Context) []*MigrationFileEntry

TODO: optimize to read from last, and break when commit status is true

func ParseMigrationEntry

func ParseMigrationEntry(migrationEntry string) (*MigrationFileEntry, error)

func (*MigrationFileEntry) EntryString

func (r *MigrationFileEntry) EntryString() string

func (*MigrationFileEntry) FileNames

func (r *MigrationFileEntry) FileNames(extention string) (string, string)

func (*MigrationFileEntry) LoadFileContent

func (r *MigrationFileEntry) LoadFileContent() (string, string)

func (*MigrationFileEntry) String

func (r *MigrationFileEntry) String() string

type MigrationType

type MigrationType string
const (
	MigrationUp   MigrationType = "up"
	MigrationDown MigrationType = "down"
)

type Migrations

type Migrations []*MigrationFileEntry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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