Documentation
¶
Index ¶
- type Config
- type Controller
- func (c *Controller) AddRecord(filename string, migrationType string, name string, appliedAt *time.Time)
- func (c *Controller) AlreadyApplied(filename string) bool
- func (c *Controller) HistoryLength() int
- func (c *Controller) Migrations() []string
- func (c *Controller) Save(ctx context.Context) error
- func (c *Controller) UnappliedMigrations() []string
- type FileHeader
- type FileV1
- type History
- type Record
- type RecordV1
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // MigrationDir is a path to directory where migration files are stored. MigrationDir string // Storage is an interface of factory method for Storage Storage storage.Config }
Config is a set of configurations for migration history management.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller manages a migration history.
func NewController ¶
NewController returns a new Controller instance.
func (*Controller) AddRecord ¶
func (c *Controller) AddRecord(filename string, migrationType string, name string, appliedAt *time.Time)
AddRecord adds a record to history. This method doesn't persist history. Call Save() to save the history. If appliedAt is nil, a timestamp is automatically set to time.Now().
func (*Controller) AlreadyApplied ¶
func (c *Controller) AlreadyApplied(filename string) bool
AlreadyApplied returns true if a given migration file has already been applied.
func (*Controller) HistoryLength ¶
func (c *Controller) HistoryLength() int
HistoryLength returns a number of records in history.
func (*Controller) Migrations ¶ added in v0.2.13
func (c *Controller) Migrations() []string
Migrations returns a list of all migration file names.
func (*Controller) Save ¶
func (c *Controller) Save(ctx context.Context) error
Save persists a current state of historyFile to storage.
func (*Controller) UnappliedMigrations ¶
func (c *Controller) UnappliedMigrations() []string
UnappliedMigrations returns a list of migration file names which have not been applied yet.
type FileHeader ¶
type FileHeader struct { // Version is a file format version. Version int `json:"version"` }
FileHeader contains a meta data for file format.
type FileV1 ¶
type FileV1 struct { // Version is a file format version. It is always set to 1. Version int `json:"version"` // Records is a set of applied migration log. // Only success migrations are recorded. // A key is migration file name. // We record only the file name not to invalidate history when the migration // directory is moved. Records map[string]RecordV1 `json:"records"` }
FileV1 represents a data structure for history file format v1. This is redundant and almost the same as History, but defines a separate data structure for persistence in case of future format changes.
type History ¶
type History struct {
// contains filtered or unexported fields
}
History records applied migration logs.
func ParseHistoryFile ¶
ParseHistoryFile parses bytes and returns a History instance.
func (*History) Add ¶
Add adds a new record to history. If a given filename already exists, it updates the existing record.
type Record ¶
type Record struct { // Type is a migration type. Type string // Name is a migration name. Name string // AppliedAt is a timestamp when the migration was applied. // Note that we only record it when the migration was succeed. AppliedAt time.Time }
Record represents an applied migration log.
type RecordV1 ¶
type RecordV1 struct { // Type is a migration type. Type string `json:"type"` // Name is a migration name. Name string `json:"name"` // AppliedAt is a timestamp when the migration was applied. // Note that we only record it when the migration was succeed. AppliedAt time.Time `json:"applied_at"` }
RecordV1 represents an applied migration log.