migration

package
v0.0.0-...-bf83fb3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package migration provides automatic database migration capabilities Basic Usage sample:

Errors should be handled, but ignored for example code migrator, _ := migration.NewMigrator(db *sql.Connection) _ = migrator.AddMigrationList(arc.GetMigrationList()) // See below _ = migrator.Upgrade()

Example package that defines migrations var migrations embed.FS

const (

MIGRATION_CODE = "arc"

)

// GetMigrationList returns this packages migration list

func GetMigrationList() (ml *migration.List) {
	return migration.NewList(MIGRATION_CODE, migration.MIGRATION_PATH, migrations)
}

Index

Constants

View Source
const (
	ECode000201 = e.Code0002 + "01"
	ECode000202 = e.Code0002 + "02"
	ECode000203 = e.Code0002 + "03"
	ECode000204 = e.Code0002 + "04"
	ECode000205 = e.Code0002 + "05"
	ECode000206 = e.Code0002 + "06"
)
View Source
const (
	MIGRATION_TABLE = "skyrin_migration"
	MIGRATION_PATH  = "db/migrations"
	MIGRATION_CODE  = "migration"

	ECode000101 = e.Code0001 + "01"
	ECode000102 = e.Code0001 + "02"
	ECode000103 = e.Code0001 + "03"
	ECode000104 = e.Code0001 + "04"
	ECode000105 = e.Code0001 + "05"
	ECode000106 = e.Code0001 + "06"
	ECode000107 = e.Code0001 + "07"
	ECode000108 = e.Code0001 + "08"
	ECode000109 = e.Code0001 + "09"
	ECode00010A = e.Code0001 + "0A"
	ECode00010B = e.Code0001 + "0B"
	ECode00010C = e.Code0001 + "0C"
	ECode00010D = e.Code0001 + "0D"
	ECode00010E = e.Code0001 + "0E"
	ECode00010F = e.Code0001 + "0F"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Name    string
	Version int
	SQL     []byte
}

func (*File) GetVersionFromName

func (f *File) GetVersionFromName() (v int, err error)

GetVersionFromName parse the name for the version. The name is expected to have the version first as a 0 padded number and then an underscore. The rest of the name can be anything.

type List

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

func NewList

func NewList(code, path string, migrations embed.FS) (l *List)

NewList initialize a new list

func (List) GetLatestMigrationFiles

func (l List) GetLatestMigrationFiles(v int) (fList []*File, err error)

GetLatestMigrationFiles gets all migration files after the specified version from the migration list's embeded file system

type Migrator

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

func NewMigrator

func NewMigrator(db *sql.Connection) (m *Migrator, err error)

NewMigrator initializes a new migrator

func (*Migrator) AddMigrationList

func (m *Migrator) AddMigrationList(ml *List) (err error)

AddMigrationList adds a migration list to the migrator

func (*Migrator) Upgrade

func (m *Migrator) Upgrade() (err error)

Upgrade runs upgrades on all migration lists

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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