Documentation
¶
Index ¶
- Constants
- Variables
- func FileWriter(ins *FOFM) error
- func MigrationFileNameTime(name string) (timestamp time.Time, err error)
- func MigrationNameParts(name string) (timestamp time.Time, direction string, err error)
- type BaseMigration
- type FOFM
- type FunctionalMigration
- type Migration
- type MigrationSet
- type MigrationSetStatus
- type MigrationStack
- func (m *MigrationStack) Add(name, direction string, timestamp time.Time) error
- func (m MigrationStack) After(after *Migration) MigrationStack
- func (m MigrationStack) BeforeName(name string) MigrationStack
- func (m MigrationStack) First() *Migration
- func (m MigrationStack) Last() *Migration
- func (m MigrationStack) Names() []string
- func (m MigrationStack) Order()
- func (m MigrationStack) Reverse()
- type NoResultsError
- type Run
- type SQLite
- func (s *SQLite) ClearStore() error
- func (s *SQLite) Close() error
- func (s *SQLite) Connect() error
- func (s *SQLite) CreateStore() error
- func (s *SQLite) GetAllByName(name string) (MigrationSet, error)
- func (s *SQLite) LastRun() (*Migration, error)
- func (s *SQLite) LastRunByName(name string) (*Migration, error)
- func (s *SQLite) LastStatusRun(status string) (*Migration, error)
- func (s *SQLite) List() (MigrationSet, error)
- func (s *SQLite) Save(current Migration, err error) error
- type Setting
- type Status
- type Store
- type WriteFile
Constants ¶
const ( STATUS_SUCCESS = "success" STATUS_FAILURE = "failure" )
Variables ¶
var DefaultSettings = []Setting{ FileWriter, }
Functions ¶
func FileWriter ¶
FileWriter sets the writer to be the deafult file writer
func MigrationFileNameTime ¶
Types ¶
type BaseMigration ¶
type BaseMigration struct{}
BaseMigration provides an embed struct to easily adhere to the FunctionalMigration interface
func (BaseMigration) GetMigrationsPath ¶
func (b BaseMigration) GetMigrationsPath() string
type FOFM ¶
type FOFM struct {
DB Store
Migration FunctionalMigration
UpMigrations MigrationStack
DownMigrations MigrationStack
Seeded bool
Writer WriteFile
// contains filtered or unexported fields
}
func New ¶
func New(db Store, migrationInstance FunctionalMigration, settings ...Setting) (*FOFM, error)
New will creae a new instance of FOFM. It will apply the DefaultSettings which can be overwritten by passing in settings
func (*FOFM) ClearStore ¶
func (*FOFM) CreateMigration ¶
CreateMigration will create a new migration template based on the current unix time and it will call the defined Writer (which is a file writer by default)
func (*FOFM) Down ¶
Down will run all migrations, in reverse order, up to and including the named one passed in
func (*FOFM) GetNextMigrationTemplate ¶
GetNextMigrationTemplate will return a migration template and its unix time
func (*FOFM) Latest ¶
Latest will run all up migrations between the last migration that was run and the latest defined migration. If the last migration was a failure, it will attempt to rerun it if the last run migration is the latest and it was successful, it will return an error. If that migration was a failure, it will attempt to rerun it
func (*FOFM) Status ¶
func (m *FOFM) Status() (MigrationSetStatus, error)
Status returns a list of all migrations and all of the times when they've been run since migrations can be run mulitple times
type FunctionalMigration ¶
type FunctionalMigration interface {
// GetMigrationsPath this should return the directory where your migration
// manager lives. This path is used when new migration files are created
GetMigrationsPath() string
// GetPackageName should return the name of the package where your migration
// manager lives. This is sued when migration files are created
GetPackageName() string
}
type Migration ¶
type Migration struct {
ID int `json:"id"`
Name string `json:"name"`
Direction string `json:"direction"`
Status string `json:"status"`
Error string `json:"error"`
Timestamp time.Time `json:"timestamp"`
Created time.Time `json:"created"`
// contains filtered or unexported fields
}
func (*Migration) CreatedFromString ¶
func (*Migration) TimestampFromString ¶
type MigrationSet ¶
type MigrationSet []Migration
func (MigrationSet) ToRuns ¶
func (m MigrationSet) ToRuns() []Run
type MigrationSetStatus ¶
type MigrationSetStatus struct {
Migrations []Status `json:"migration_statuses"`
// contains filtered or unexported fields
}
type MigrationStack ¶
type MigrationStack []Migration
func (*MigrationStack) Add ¶
func (m *MigrationStack) Add(name, direction string, timestamp time.Time) error
func (MigrationStack) After ¶
func (m MigrationStack) After(after *Migration) MigrationStack
func (MigrationStack) BeforeName ¶
func (m MigrationStack) BeforeName(name string) MigrationStack
func (MigrationStack) First ¶
func (m MigrationStack) First() *Migration
func (MigrationStack) Last ¶
func (m MigrationStack) Last() *Migration
func (MigrationStack) Names ¶
func (m MigrationStack) Names() []string
func (MigrationStack) Order ¶
func (m MigrationStack) Order()
func (MigrationStack) Reverse ¶
func (m MigrationStack) Reverse()
type NoResultsError ¶
type NoResultsError struct {
OriginalError error
// contains filtered or unexported fields
}
NoResultsError should be used in place of a store's no results error
func (NoResultsError) Error ¶
func (re NoResultsError) Error() string
type SQLite ¶
type SQLite struct {
// contains filtered or unexported fields
}
func NewSQLiteWithTableName ¶
func (*SQLite) ClearStore ¶
func (*SQLite) CreateStore ¶
func (*SQLite) GetAllByName ¶
func (s *SQLite) GetAllByName(name string) (MigrationSet, error)
func (*SQLite) List ¶
func (s *SQLite) List() (MigrationSet, error)
type Store ¶
type Store interface {
// Connect will connect to the store
// it is automatcically called by FOFM
Connect() error
// Close will close any connections related to the store
Close() error
// CreateStore should do the work of creating
// the storage for the migrations. It
// should be a "create if doesnt exist" type
// operation
CreateStore() error
// ClearStore should reset the store to an empty state
ClearStore() error
// LastRun will return the last run migration
LastRun() (*Migration, error)
// LastStatusRun will get the last run with the
// provided status
LastStatusRun(status string) (*Migration, error)
// LastRunByName will get the last run with the
// provided name
LastRunByName(name string) (*Migration, error)
// GetAllByName will return all migrations with the
// provided name
GetAllByName(name string) (MigrationSet, error)
// List will return a list of all migrations that
// have been saved to the store
List() (MigrationSet, error)
// Save should insert a new record
Save(current Migration, err error) error
}