migrator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migrator

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

func NewMigrator

func NewMigrator(logger *zap.Logger, repository database.Repository, config *conf.MigrationConfig) *Migrator

func (*Migrator) Migrate

func (m *Migrator) Migrate() error

Migrate performs database migrations based on the configuration and current state of the database. It handles both "up" and "down" migrations, validates migrations if configured, and ensures the schema history table exists. The function operates within a distributed lock to prevent concurrent migrations.

Steps:

  1. Load migrations and hooks from the filesystem.
  2. Ensure the schema history table exists.
  3. Determine the latest applied migration version.
  4. Validate migrations (if enabled in the configuration).
  5. Determine the target migration version (destination).
  6. Execute the appropriate migration (up or down) based on the configuration.
  7. Log errors and warnings throughout the process.

Jump to

Keyboard shortcuts

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