history

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

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

func NewController(ctx context.Context, migrationDir string, config *Config) (*Controller, error)

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.

func (*FileV1) Serialize

func (f *FileV1) Serialize() ([]byte, error)

Serialize encodes a FileV1 instance to bytes.

type History

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

History records applied migration logs.

func ParseHistoryFile

func ParseHistoryFile(b []byte) (*History, error)

ParseHistoryFile parses bytes and returns a History instance.

func (*History) Add

func (h *History) Add(filename string, r Record)

Add adds a new record to history. If a given filename already exists, it updates the existing record.

func (*History) Clear

func (h *History) Clear()

Clear deletes all records from history.

func (*History) Contains

func (h *History) Contains(filename string) bool

Contains returns true if a given migration has been applied.

func (*History) Delete

func (h *History) Delete(filename string)

Delete deletes a record from history. If a given filename doesn't exist, no-op.

func (*History) Length

func (h *History) Length() int

Length returns a number of records in history.

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.

Jump to

Keyboard shortcuts

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