dbmigrator

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 10 Imported by: 5

README

dbmigrator

Custom SQLDB migrator

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppliedMigration

type AppliedMigration struct {
	ID          int       `db:"id"`
	Description string    `db:"description"`
	AppliedAt   time.Time `db:"applied_at"`
}

AppliedMigration is a struct that contains the status of a migration.

type Migration

type Migration struct {
	ID          int
	Description string
	SQL         string
}

Migration is a struct that contains the migration.

type Migrator

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

Migrator is a struct that contains all the methods to interact with the migrations table in the database.

func NewMigrator

func NewMigrator(
	ctx context.Context,
	db *sqlx.DB,
	upMigrations, downMigrations embed.FS,
	opts *Options,
) (*Migrator, error)

NewMigrator creates a new migrator.

func (*Migrator) GetLastMigrationID

func (m *Migrator) GetLastMigrationID(ctx context.Context) (int, error)

GetLastMigrationID returns the last migration ID.

func (*Migrator) MigrateTo

func (m *Migrator) MigrateTo(ctx context.Context, id int) error

MigrateTo will apply the migrations up to the specified ID.

func (*Migrator) MigrateToLatest

func (m *Migrator) MigrateToLatest(ctx context.Context) error

MigrateToLatest will apply all the migrations that have not been applied yet.

func (*Migrator) Rollback

func (m *Migrator) Rollback(ctx context.Context) error

Rollback will rollback the last migration.

func (*Migrator) RollbackUntil

func (m *Migrator) RollbackUntil(ctx context.Context, id int) error

RollbackUntil will rollback the migrations until the specified ID.

type Options

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

Options represents the options for the migrator.

Jump to

Keyboard shortcuts

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