Documentation
¶
Index ¶
- Variables
- func CreateMigrationEntry(table string) string
- func CreateMigrationTable(table string) string
- func DeleteMigrationEntry(table string) string
- func DropMigrationTable(table string) string
- func IsEmpty(store Store, schemaTable string) bool
- func IsTracked(store Store, schemaTable string) bool
- func IsUpToDate(store Store, schemaTable string, migrations MigrationList) bool
- func LoadFiles(dir string, pattern *regexp.Regexp) []fs.FileInfo
- func MatchingFiles(dir string, pattern *regexp.Regexp) ([]fs.FileInfo, error)
- func NumberOfAppliedMigrations(table string) string
- func SchemaTableExists(table string) string
- func SelectMigrationEntry(table string) string
- func SelectMigrations(table string) string
- func SelectMigrationsVersion(table string) string
- func StartTracking(store Store, schemaTable string) bool
- func StopTracking(store Store, schemaTable string) bool
- func Validate(migrations MigrationList) (bool, string)
- type Changes
- type DatabaseConnector
- type Engine
- type EngineError
- type FileLoader
- type Migration
- type MigrationFile
- type MigrationList
- func (List *MigrationList) Description() string
- func (List *MigrationList) Find(identifier string) (sequence MigrationList, isFound bool)
- func (List *MigrationList) FromMap(m map[string]Migration)
- func (List *MigrationList) GetHead() *Migration
- func (List *MigrationList) GetTail() *Migration
- func (List *MigrationList) Insert(node *Migration)
- func (List *MigrationList) IsEmpty() bool
- func (List *MigrationList) Remove(identifier string)
- func (List *MigrationList) Reverse()
- func (List *MigrationList) Size() int
- func (List *MigrationList) ToMap() map[string]Migration
- func (List *MigrationList) ToSlice() Migrations
- type MigrationRunner
- type Migrations
- type MigratorVersion
- type Runner
- func (runner *Runner) AppliedMigrations(directory string, filePattern *regexp.Regexp, loadFromDir bool) MigrationList
- func (runner *Runner) Down(migrations MigrationList) error
- func (runner *Runner) Generate(name string, directory string) Migration
- func (runner *Runner) GetSchemaTable() string
- func (runner *Runner) GetStore() Store
- func (runner *Runner) LogError(err string)
- func (runner *Runner) LogInfo(info string)
- func (runner *Runner) PendingMigrations(directory string, filePattern *regexp.Regexp) MigrationList
- func (runner *Runner) SetLogger(format, template string)
- func (runner *Runner) SetSchemaTable(table string)
- func (runner *Runner) SetStore(store Store)
- func (runner *Runner) Up(migrations MigrationList) error
- func (runner *Runner) Version() (MigratorVersion, bool)
- type Store
- type TableSchema
- type Tracker
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( FilePattern = *regexp.MustCompile(`(?P<Version>^\d{20})_(?P<Name>[aA-zZ]+).yaml$`) CreateTablePattern = *regexp.MustCompile(`CREATE TABLE (?P<TableName>\w+)`) DropTablePattern = *regexp.MustCompile(`(DROP TABLE (IF EXISTS )?)(?P<TableName>\w+)`) )
Functions ¶
func CreateMigrationEntry ¶
func CreateMigrationTable ¶
func DeleteMigrationEntry ¶
func DropMigrationTable ¶
func IsTracked ¶
MARK: - Returns `true` if the schemaTable is found in the database. Returns `false` in any other case.
func IsUpToDate ¶
func IsUpToDate(store Store, schemaTable string, migrations MigrationList) bool
func MatchingFiles ¶
MatchingFiles - Finds all files that statisfy a regex in the specified directory
func SchemaTableExists ¶
func SelectMigrationEntry ¶
func SelectMigrations ¶
func SelectMigrationsVersion ¶
func StartTracking ¶
func StopTracking ¶
func Validate ¶
func Validate(migrations MigrationList) (bool, string)
Validate - Runs validations on a list of migrations.
Types ¶
type DatabaseConnector ¶
type Engine ¶
type Engine interface { // DatabaseConnector FileLoader MigrationRunner Tracker Validator }
type EngineError ¶
type EngineError struct{}
func (EngineError) Error ¶
func (error EngineError) Error() string
type FileLoader ¶
type Migration ¶
type Migration struct { Id int `yaml:"-" json:"-"` FileName string `yaml:"-"` Version string `yaml:"version"` Schema int `yaml:"schema,omitempty" json:"-"` Name string `yaml:"name"` Engine string `yaml:"engine" json:"-"` Changes Changes `yaml:"changes,omitempty" json:"-"` // contains filtered or unexported fields }
func (Migration) Description ¶
type MigrationFile ¶
type MigrationFile struct {
// contains filtered or unexported fields
}
func (MigrationFile) IsDir ¶
func (f MigrationFile) IsDir() bool
func (MigrationFile) ModTime ¶
func (f MigrationFile) ModTime() time.Time
func (MigrationFile) Mode ¶
func (f MigrationFile) Mode() fs.FileMode
func (MigrationFile) Name ¶
func (f MigrationFile) Name() string
func (MigrationFile) Size ¶
func (f MigrationFile) Size() int64
func (MigrationFile) Sys ¶
func (f MigrationFile) Sys() any
type MigrationList ¶
type MigrationList struct {
// contains filtered or unexported fields
}
func BuildMigrations ¶
BuildMigrations - Instantiate a list of migrations from the contents of the provided files. Accesses the filesystem.
func (*MigrationList) Description ¶
func (List *MigrationList) Description() string
func (*MigrationList) Find ¶
func (List *MigrationList) Find(identifier string) (sequence MigrationList, isFound bool)
Find - Traverses the list in search for a given node.
func (*MigrationList) FromMap ¶
func (List *MigrationList) FromMap(m map[string]Migration)
FromMap - Inserts map elements into the list.
func (*MigrationList) GetHead ¶
func (List *MigrationList) GetHead() *Migration
GetHead - Returns the node at the start of the list.
func (*MigrationList) GetTail ¶
func (List *MigrationList) GetTail() *Migration
GetTail - Returns the node at the end of the list.
func (*MigrationList) Insert ¶
func (List *MigrationList) Insert(node *Migration)
Insert - Adds a new node to the end of the list.
func (*MigrationList) IsEmpty ¶
func (List *MigrationList) IsEmpty() bool
func (*MigrationList) Remove ¶
func (List *MigrationList) Remove(identifier string)
Remove - Excludes a node from the list.
func (*MigrationList) Reverse ¶
func (List *MigrationList) Reverse()
Reverse - Traverses list and swaps the direction of the list.
func (*MigrationList) Size ¶
func (List *MigrationList) Size() int
func (*MigrationList) ToMap ¶
func (List *MigrationList) ToMap() map[string]Migration
ToMap - Transforms the list into a map.
func (*MigrationList) ToSlice ¶
func (List *MigrationList) ToSlice() Migrations
ToSlice - Transforms the list into a slice.
type MigrationRunner ¶
type MigrationRunner interface { // Up - Runs migrations Up(changes MigrationList) error // Down - Reverts migrations Down(changes MigrationList) error }
type Migrations ¶
type Migrations []Migration
func (Migrations) Description ¶
func (m Migrations) Description() string
MARK: - Implements Formattable
func (Migrations) Len ¶
func (m Migrations) Len() int
func (Migrations) Less ¶
func (m Migrations) Less(left, right int) bool
func (Migrations) Swap ¶
func (m Migrations) Swap(left, right int)
func (Migrations) ToHash ¶
func (m Migrations) ToHash() map[string]Migration
type MigratorVersion ¶
type MigratorVersion struct { Id int `json:"id"` Name string `json:"name"` Version string `json:"version"` CreatedAt time.Time `json:"created_at" db:"created_at"` }
func (*MigratorVersion) Description ¶
func (V *MigratorVersion) Description() string
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner:
Responsible for running and reverting migrations. The migration and rollback algorithm is self-contained within this type. For more flexibility, creations, reads, and deletions are responsibilities of the underlying store type. You can inject a type that conforms to the `Store` interface, and the `Runner` will call the store's appropriate methods when needed.
func (*Runner) AppliedMigrations ¶
func (*Runner) Down ¶
func (runner *Runner) Down(migrations MigrationList) error
func (*Runner) GetSchemaTable ¶
func (*Runner) PendingMigrations ¶
func (runner *Runner) PendingMigrations(directory string, filePattern *regexp.Regexp) MigrationList
func (*Runner) SetSchemaTable ¶
func (*Runner) Up ¶
func (runner *Runner) Up(migrations MigrationList) error
func (*Runner) Version ¶
func (runner *Runner) Version() (MigratorVersion, bool)
type Store ¶
type Store interface { // Create - Adds record(s) to the store. Create(string, ...interface{}) error // Read - Reads record from the store. Read(string, interface{}, ...interface{}) error // Delete - Removes record(s) from the store. Delete(string, ...interface{}) error // Name - A string that identifies this store. Name() string DatabaseURL() string }
type TableSchema ¶
type Tracker ¶
type Tracker interface { // ... - BuildMigrations([]fs.FileInfo) MigrationList // StartTracking - Prepares database for migration tracking StartTracking() error // StopTracking - Stops tracking database migrations StopTracking() error // Version - Return the version of the last applied migration. The returned boolean should indicate if the database is being tracked Version() (string, bool) // IsUpToDate - Indicator of whether migrations are current or up-to-date IsUpToDate(changes MigrationList) bool // IsTracked - Indicator of whether the database is being managed by this tool IsTracked() bool // IsEmpty - Indicator of whether the database has any migrations IsEmpty() bool // AppliedMigrations - Returns all applied/saved migrations AppliedMigrations() MigrationList // PendingMigrations - Returns all non-applied/saved migrations. PendingMigrations() MigrationList }
type ValidationError ¶
type ValidationError struct{}
func (ValidationError) Error ¶
func (error ValidationError) Error() string
type Validator ¶
type Validator interface { // Validate - Given a set of migrations, this method should return whether or not the migrations are valid. Validate(changes MigrationList) (bool, string) }