migrator

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunMigrations

func RunMigrations(
	d types.Querier, migrations []*Migration, typ MigrationType, to string,
	logger *slog.Logger,
) error

RunMigrations applies or rolls back migrations. to can either be a migration name, or "all".

Types

type Migration

type Migration struct {
	ID      int64
	Name    string
	Applied bool
	History []MigrationEvent
	Up      sql.Null[string]
	Down    sql.Null[string]
}

Migration is a database migration.

func LoadMigrations

func LoadMigrations(dir fs.FS) ([]*Migration, error)

LoadMigrations reads SQL files from the embedded directory, and returns a slice of Migration sorted by migration name.

type MigrationEvent

type MigrationEvent struct {
	Type MigrationType
	Time time.Time
}

MigrationEvent is a record of a migration being applied or rolled back.

type MigrationType

type MigrationType string

MigrationType is the type of the migration.

const (
	MigrationUp   MigrationType = "up"
	MigrationDown MigrationType = "down"
)

Migration types.

Jump to

Keyboard shortcuts

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