Documentation
¶
Index ¶
Constants ¶
const ( ErrPathNotFound = utils.Error("Specified migration path not found") ErrInvalidPath = utils.Error("Specified migration path is not a directory") ErrInvalidFile = utils.Error("Specified migration path is not a file") ErrReadMigration = utils.Error("Error reading migration") MigrationFileExtension = ".sql" )
const ( ModuleBase = "base" MsgSkipMigration = iota + 1 MsgRunMigration MsgFinishedMigration MsgError ErrMigrationNameHashMismatch = utils.Error("Migration name or hash exists but they mismatch. Migration file was edited or renamed?") ErrMigrationExists = utils.Error("Migration already executed") ErrRegisterMigration = utils.Error("Migration executed successfully, but registration failed. Register manually") )
const (
ErrEmptyFolder = utils.Error("Specified folder is empty")
)
const (
ErrFileNotFound = utils.Error("file not found")
)
const ( // ErrMissingVar is a placeholder the caller supplied no value for. It is an // error rather than an empty string: an unresolved name would otherwise // reach the server as literal text, usually inside a GRANT or an owner // clause, and fail in a way that names nothing useful. ErrMissingVar = utils.Error("migration placeholder has no value") )
Variables ¶
This section is empty.
Functions ¶
func DefaultProgressFn ¶
Types ¶
type DiskSource ¶
type DiskSource struct {
Path string
}
func (*DiskSource) Read ¶
func (d *DiskSource) Read(name string) (*MigrationRecord, error)
Read a migration from disk
type EmbedSource ¶
type EmbedSource struct {
// contains filtered or unexported fields
}
func (*EmbedSource) List ¶
func (d *EmbedSource) List() ([]string, error)
List sql files (migrations)
func (*EmbedSource) Read ¶
func (d *EmbedSource) Read(name string) (*MigrationRecord, error)
Read a migration from disk
type Manager ¶
type Manager interface {
List(ctx context.Context) ([]MigrationRecord, error)
MigrationExists(ctx context.Context, name string, sha2 string) (bool, error)
RunMigration(ctx context.Context, m *MigrationRecord) error
RegisterMigration(ctx context.Context, m *MigrationRecord) error
Run(ctx context.Context, src Source, consoleFn ProgressFn) error
}
type MemorySource ¶ added in v0.1.4
type MemorySource struct {
// contains filtered or unexported fields
}
func NewMemorySource ¶ added in v0.1.4
func NewMemorySource() *MemorySource
func (*MemorySource) Add ¶ added in v0.1.4
func (d *MemorySource) Add(name string, content string)
Add a migration
func (*MemorySource) List ¶ added in v0.1.4
func (d *MemorySource) List() ([]string, error)
List sql files (migrations)
func (*MemorySource) Read ¶ added in v0.1.4
func (d *MemorySource) Read(name string) (*MigrationRecord, error)
Read a migration
type MigrationRecord ¶
type MigrationRecord struct {
Created time.Time `db:"created" ch:"created"`
Module string `db:"module" ch:"module"`
Name string `db:"name" ch:"name"`
SHA2 string `db:"sha2" ch:"sha2"`
Contents string `db:"contents" ch:"contents"`
}
func LoadMigration ¶
func LoadMigration(name string, content []byte) (*MigrationRecord, error)
LoadMigration from []byte slice
type ProgressFn ¶
type Source ¶
type Source interface {
List() ([]string, error)
Read(name string) (*MigrationRecord, error)
}
func NewDiskSource ¶
func Substitute ¶ added in v0.10.0
Substitute wraps a Source, replacing ${name} in every migration it reads with the value given. It is how a deployment-specific identifier -- the role an application connects as, a schema, a tablespace -- reaches DDL that is otherwise fixed.
The recorded SHA2 stays the TEMPLATE's, not the substituted text's, while the recorded contents are what actually ran. That asymmetry is deliberate: a migration's identity is the file as shipped, so a deployment that changes one of these values does not make its applied migrations look edited. Two consequences are worth knowing: re-hashing a stored `contents` does not reproduce its `sha2` for any migration that carried a placeholder, and changing a value does not re-run a migration that already ran -- migrations are skipped by name, so a new value needs a new migration.
Substitution is textual and has no logic: there is no way to express a condition or a loop, so the SQL that runs is the SQL that was shipped with its identifiers filled in, and nothing else.
src must not be nil.
type Vars ¶ added in v0.10.0
Vars are the values a migration's placeholders are substituted with, keyed by the name inside ${...}. A value is spliced into the SQL verbatim, with no quoting or escaping, so it must be a trusted identifier; it is not a way to pass data to a statement, and it must never carry a secret, because the substituted text is stored in the migration table.