Documentation
¶
Index ¶
- func AddMigrationContext(up, down MigrationContext)
- func AddNamedMigrationContext(source string, up, down MigrationContext)
- func Create(dir, name string) error
- func ResetRegisteredMigrations()
- type Migrate
- func (m *Migrate) Close() error
- func (m *Migrate) Create(name string) error
- func (m *Migrate) Down(opts ...Option) error
- func (m *Migrate) DownContext(ctx context.Context, opts ...Option) error
- func (m *Migrate) DownTo(version int64, opts ...Option) error
- func (m *Migrate) DownToContext(ctx context.Context, version int64, opts ...Option) error
- func (m *Migrate) Reset(opts ...Option) error
- func (m *Migrate) ResetContext(ctx context.Context, opts ...Option) error
- func (m *Migrate) Status() error
- func (m *Migrate) StatusContext(ctx context.Context) error
- func (m *Migrate) Up(opts ...Option) error
- func (m *Migrate) UpContext(ctx context.Context, opts ...Option) error
- func (m *Migrate) UpTo(version int64, opts ...Option) error
- func (m *Migrate) UpToContext(ctx context.Context, version int64, opts ...Option) error
- type Migration
- type MigrationContext
- type MigrisOption
- type Option
- type Registry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddMigrationContext ¶
func AddMigrationContext(up, down MigrationContext)
AddMigrationContext adds Go migrations to the default registry.
func AddNamedMigrationContext ¶
func AddNamedMigrationContext(source string, up, down MigrationContext)
AddNamedMigrationContext adds named Go migrations to the default registry.
func ResetRegisteredMigrations ¶ added in v0.4.1
func ResetRegisteredMigrations()
ResetRegisteredMigrations clears the default global registry of migrations. This is primarily intended for tests to avoid cross-test interference.
Types ¶
type Migrate ¶
type Migrate struct {
// contains filtered or unexported fields
}
Migrate handles database migrations.
func New ¶
func New(dialectValue string, opts ...MigrisOption) (*Migrate, error)
New creates a new Migrate instance.
func (*Migrate) Close ¶ added in v0.4.2
Close closes the database connection if it was opened by the migrator via WithDSN. If the connection was provided externally via WithDB, this is a no-op.
func (*Migrate) Create ¶
Create creates a new migration file with the given name in the specified directory.
func (*Migrate) DownContext ¶
DownContext rolls back the last migration.
func (*Migrate) DownToContext ¶
DownToContext rolls back the migrations to the specified version.
func (*Migrate) ResetContext ¶
ResetContext rolls back all migrations.
func (*Migrate) StatusContext ¶
StatusContext returns the status of the migrations.
type MigrationContext ¶
MigrationContext is a Go migration func that is run within a transaction and receives a context.
type MigrisOption ¶ added in v0.4.2
type MigrisOption func(*Migrate)
MigrisOption configures a Migrate instance at construction time.
func WithDB ¶
func WithDB(db *sql.DB) MigrisOption
WithDB sets the database connection for the migration.
func WithDSN ¶ added in v0.4.2
func WithDSN(dsn string) MigrisOption
WithDSN opens a database connection from the given DSN string. The migrator takes ownership of the connection; call Close when done.
func WithMigrationDir ¶
func WithMigrationDir(dir string) MigrisOption
WithMigrationDir sets the directory for the migration files.
func WithRegistry ¶ added in v0.4.1
func WithRegistry(registry *Registry) MigrisOption
WithRegistry sets the migration registry for the migrator.
func WithTableName ¶
func WithTableName(name string) MigrisOption
WithTableName sets the table name for the migration.
type Option ¶
type Option func(*runOptions)
Option configures a single run operation (Up, Down, Reset, etc.).
func WithAllowMissing ¶ added in v0.4.2
WithAllowMissing allows out-of-order migrations to be applied.
func WithDryRun ¶ added in v0.4.0
WithDryRun simulates the migration without applying changes.
type Registry ¶ added in v0.4.1
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶ added in v0.4.1
func NewRegistry() *Registry
NewRegistry creates an isolated migration registry.
func (*Registry) AddMigrationContext ¶ added in v0.4.1
func (r *Registry) AddMigrationContext(up, down MigrationContext)
AddMigrationContext adds Go migrations to the registry.
func (*Registry) AddNamedMigrationContext ¶ added in v0.4.1
func (r *Registry) AddNamedMigrationContext(source string, up, down MigrationContext) error
AddNamedMigrationContext adds named Go migrations to the registry.