migration

package
v2.6.7 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: ISC Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RESET     = "\033[0m"
	BOLD      = "\033[1m"
	UNDERLINE = "\033[4m"
	STRIKE    = "\033[9m"
	ITALIC    = "\033[3m"
)
View Source
const (
	RED    = "\033[31m"
	GREEN  = "\033[32m"
	YELLOW = "\033[33m"
	BLUE   = "\033[34m"
	PURPLE = "\033[35m"
	CYAN   = "\033[36m"
	GRAY   = "\033[37m"
	WHITE  = "\033[37m"
)

Variables

This section is empty.

Functions

func Formatter added in v2.2.4

func Formatter(pattern string, args ...any)

styling patterns

{R}: RESET, {B}: BOLD ,{U}: UNDERLINE ,{S}: STRIKE {I}: ITALIC ,{r}: RED ,{g}: GREEN ,{y}: YELLOW

{b}: BLUE ,{p}: PURPLE ,{c}: CYAN ,{m}: GRAY {w}: WHITE

func MigrationCommand

func MigrationCommand(driver Migration, autExec ...string) *cobra.Command

MigrationCommand migration cli commands

func NewMigrationFile added in v2.6.0

func NewMigrationFile(root, name, ext string, stages ...string) error

NewMigrationFile generate new migration file

Types

type FS added in v2.6.0

type FS []File

FS migration file system

func NewDirFS added in v2.6.0

func NewDirFS(root, ext string) (FS, error)

NewDirFS generate new migration filesystem from directory

func NewEmbedFS added in v2.6.0

func NewEmbedFS(f embed.FS, root, ext string) (FS, error)

NewEmbedFS generate new migration filesystem from embedded files

func (FS) Copy added in v2.6.0

func (files FS) Copy() FS

Copy create a new fresh copy from file system

func (FS) ExcludeMigrated added in v2.6.0

func (files FS) ExcludeMigrated(names ...string) FS

ExcludeMigrated exclude files from file system

func (FS) Filter added in v2.6.0

func (files FS) Filter(names ...string) FS

Filter filter files by name

func (FS) FilterMigrated added in v2.6.0

func (files FS) FilterMigrated(names ...string) FS

FilterMigrated exclude files from file system

func (FS) Len added in v2.6.0

func (files FS) Len() int

Len get files length

func (FS) Less added in v2.6.0

func (files FS) Less(i, j int) bool

Less check if name timestamp is smaller

func (FS) Reverse added in v2.6.0

func (files FS) Reverse() FS

Reverse reverse array order

func (FS) Swap added in v2.6.0

func (files FS) Swap(i, j int)

Swap swap item i and j

type File added in v2.5.0

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

File migration file

func (File) Content added in v2.5.0

func (file File) Content() string

Content get file content

func (File) DownScripts added in v2.6.0

func (file File) DownScripts(stage string) (string, error)

DownScripts get down section scripts

func (File) Extension added in v2.5.0

func (file File) Extension() string

Extension get file extension

func (File) HumanizedName added in v2.6.0

func (file File) HumanizedName() string

HumanizedName get file readable name withut timestamp and extension

func (File) Is added in v2.5.0

func (file File) Is(name string) bool

Is Compare file name in humanize format

func (File) Name added in v2.5.0

func (file File) Name() string

Name get file full name

func (File) Timestamp added in v2.5.0

func (file File) Timestamp() int64

Get timestamp part of filename

func (File) UpScripts added in v2.6.0

func (file File) UpScripts(stage string) (string, error)

UpScripts get up section scripts

type Migrated added in v2.5.0

type Migrated struct {
	Name  string `db:"name"`
	Stage string `db:"stage"`
}

type Migration added in v2.5.0

type Migration interface {
	// Root Get Root directory
	Root() string
	// Extension Get file extension
	Extension() string
	// Path get full path of file
	Path(name string) string
	// Init initialize database migration
	Init() error
	// Summary get migration summery
	Summary() (Summary, error)
	// StageSummary get migration summery for stage
	StageSummary(stage string) (Summary, error)
	// Up run migration stage
	//
	// pass only to run migrate on certain files only
	Up(stage string, only ...string) ([]string, error)
	// Down rollback migration stage
	//
	// pass only to run rollback on certain files only
	Down(stage string, only ...string) ([]string, error)
}

func NewDirMigration added in v2.6.0

func NewDirMigration(db *sqlx.DB, root, ext string) (Migration, error)

NewDirMigration create new migration instance from physical dir files

func NewEmbedMigration added in v2.6.0

func NewEmbedMigration(db *sqlx.DB, fs embed.FS, root, ext string) (Migration, error)

NewEmbedMigration create new migration instance from embedded files

func NewMigration added in v2.6.0

func NewMigration(db *sqlx.DB, fs FS, root, ext string) Migration

NewMigration create new migration instance

type Summary added in v2.6.0

type Summary []Migrated

func (Summary) GroupByFile added in v2.6.0

func (summary Summary) GroupByFile() map[string][]string

GroupByFile group migrated files by file name

func (Summary) GroupByStage added in v2.6.0

func (summary Summary) GroupByStage() map[string][]string

GroupByStage group migrated files by stage

func (Summary) IsEmpty added in v2.6.0

func (summary Summary) IsEmpty() bool

IsEmpty check if summary is empty

func (Summary) Names added in v2.6.0

func (summary Summary) Names() []string

Names get migrated files

Jump to

Keyboard shortcuts

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