migration

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DropDatabase

func DropDatabase(ctx context.Context, db *gorm.DB, provider string) error

DropDatabase drops all tables and schema

func DropTestTables

func DropTestTables(db *gorm.DB, provider string) error

DropTestTables drops all tables for testing cleanup

func ForceVersion

func ForceVersion(ctx context.Context, db *gorm.DB, provider string, version int) error

ForceVersion sets the migration version without running migrations

func GetMigrationInfo

func GetMigrationInfo(ctx context.Context, db *gorm.DB, provider string) (*domain.MigrationInfo, error)

GetMigrationInfo returns information about migration status

func RunDown

func RunDown(ctx context.Context, db *gorm.DB, provider string) error

RunDown rolls back one migration

func RunSteps

func RunSteps(ctx context.Context, db *gorm.DB, provider string, steps int) error

RunSteps runs n migrations up (positive) or down (negative)

func RunTestMigrations

func RunTestMigrations(db *gorm.DB, provider string) error

RunTestMigrations runs migrations for testing using golang-migrate with embedded files

func RunUp

func RunUp(ctx context.Context, db *gorm.DB, provider string) error

RunUp applies all pending migrations to the database

Types

type Migrator

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

Migrator handles database migrations using golang-migrate

func NewMigrator

func NewMigrator(config *MigratorConfig) (*Migrator, error)

NewMigrator creates a new migrator instance

func (*Migrator) Close

func (m *Migrator) Close() error

Close closes the migration instance

func (*Migrator) Down

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

Down runs one migration down

func (*Migrator) Drop

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

Drop drops all tables and schema

func (*Migrator) Force

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

Force sets the migration version without running migrations

func (*Migrator) GetMigrationInfo

func (m *Migrator) GetMigrationInfo(ctx context.Context) (*domain.MigrationInfo, error)

GetMigrationInfo returns information about migration status

func (*Migrator) Steps

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

Steps runs n migrations up (positive) or down (negative)

func (*Migrator) Up

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

Up runs all pending migrations

func (*Migrator) Version

func (m *Migrator) Version(ctx context.Context) (uint, bool, error)

Version returns the current migration version

type MigratorConfig

type MigratorConfig struct {
	DB            *gorm.DB
	Provider      string // "sqlite" or "postgres"
	Logger        *slog.Logger
	MigrationPath string // Path to migration files directory (e.g., "migrations/postgres")
}

MigratorConfig contains configuration for the migrator

Jump to

Keyboard shortcuts

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