Documentation ¶
Index ¶
- type Config
- type ContentGetter
- type Dialect
- type Direction
- type Migration
- type Migrator
- func (m *Migrator) AddAndSort(prefix string, migrations ...Migration) *Migrator
- func (m *Migrator) Down(ctx context.Context, db *sqlx.DB) error
- func (m *Migrator) HasDialect() bool
- func (m *Migrator) HasMigrations() bool
- func (m *Migrator) SortAndAppend(prefix string, migrations ...Migration) *Migrator
- func (m *Migrator) Up(ctx context.Context, db *sqlx.DB) error
- func (m *Migrator) WithConfig(config *Config) *Migrator
- func (m *Migrator) WithDialect(dialect Dialect) *Migrator
- type PgxDialect
- func (p *PgxDialect) BeforeMigration(ctx context.Context, db *sqlx.DB, tx *sqlx.Tx, name string, ...) error
- func (p *PgxDialect) DefaultConfig() *Config
- func (p *PgxDialect) DeleteMigration(cfg *Config) string
- func (p *PgxDialect) EnsureMigrationsTable(ctx context.Context, db *sqlx.DB, cfg *Config) error
- func (p *PgxDialect) InsertMigration(cfg *Config) string
- func (p *PgxDialect) SelectStates(cfg *Config) string
- func (p *PgxDialect) Verify(db *sqlx.DB) error
- type SQLMigration
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
func EffectiveConfig ¶
type ContentGetter ¶
type Dialect ¶
type Dialect interface { DefaultConfig() *Config Verify(db *sqlx.DB) error EnsureMigrationsTable(context.Context, *sqlx.DB, *Config) error SelectStates(*Config) string InsertMigration(*Config) string DeleteMigration(*Config) string BeforeMigration( ctx context.Context, db *sqlx.DB, tx *sqlx.Tx, name string, direction Direction, ) error }
type Migration ¶
type Migration interface { // Name is used to track whether the migration has been run, by recording the // names of migrations that have been executed in a table. Name() string // Up runs the migration in the up migration, e.g. creating new tables, to // upgrade the schema to the new state. The migration MUST perform all changes // within the given transaction, and MUST NOT terminate the transaction. Up(context.Context, *sqlx.DB, *sqlx.Tx) error // Down runs the migration in the down migration, e.g. dropping tables, to // downgrade the schema to the old state. The migration MUST perform all // changes within the given transaction, and MUST NOT terminate the // transaction. Down(context.Context, *sqlx.DB, *sqlx.Tx) error }
Migration represents a single migration that can be run to do a single atomic step of changing database schemas. Each migration will be run in an independent transaction.
func WithPrefix ¶
WithPrefix returns either the input slice if prefix is the empty string or migrations is an empty slice, or else a copy of it with prefix applied to the names.
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
func New ¶
New creates a new empty Migrator for the given config & dialect. You must add migrations to it before it can be run.
func NewFromFS ¶
func NewFromFS( config *Config, dialect Dialect, migrationsFS fs.FS, filter func(*SQLMigration) bool, ) (*Migrator, error)
NewFromFS is roughly equivalent to New(...).Add("", LoadFS(...)...). If you want to apply a prefix, use the individual method calls.
func (*Migrator) AddAndSort ¶
AddAndSort adds the listed migrations, applying the given prefix, to the migrator and sorts the resulting list
func (*Migrator) HasDialect ¶
func (*Migrator) HasMigrations ¶
func (*Migrator) SortAndAppend ¶
SortandAppend sorts the listed migrations and then appends them to the migrator without further sorting.
func (*Migrator) WithConfig ¶
func (*Migrator) WithDialect ¶
type PgxDialect ¶
type PgxDialect struct{}
func (*PgxDialect) BeforeMigration ¶
func (*PgxDialect) DefaultConfig ¶
func (p *PgxDialect) DefaultConfig() *Config
func (*PgxDialect) DeleteMigration ¶
func (p *PgxDialect) DeleteMigration(cfg *Config) string
func (*PgxDialect) EnsureMigrationsTable ¶
func (*PgxDialect) InsertMigration ¶
func (p *PgxDialect) InsertMigration(cfg *Config) string
func (*PgxDialect) SelectStates ¶
func (p *PgxDialect) SelectStates(cfg *Config) string
type SQLMigration ¶
type SQLMigration struct {
// contains filtered or unexported fields
}
func FromContent ¶
func FromContent(name string, up, down ContentGetter) *SQLMigration
FromContent generates a SQL Migration from dynamic SQL script getters.
func FromSQL ¶
func FromSQL(name, up, down string) *SQLMigration
FromSQL generates a SQL Migration based on fixed SQL scripts.
func (*SQLMigration) Name ¶
func (m *SQLMigration) Name() string