migrations

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLIManager

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

CLIManager handles CLI operations for migrations

func NewCLIManager

func NewCLIManager(provider database.DatabaseProvider, migrationsDir string, logger *logrus.Logger) *CLIManager

NewCLIManager creates a new CLI manager

func (*CLIManager) CreateMigration

func (cm *CLIManager) CreateMigration(name string) error

CreateMigration creates a new migration file

func (*CLIManager) CreateMigrationsDirectory

func (cm *CLIManager) CreateMigrationsDirectory() error

CreateMigrationsDirectory creates the migrations directory if it doesn't exist

func (*CLIManager) Down

func (cm *CLIManager) Down(ctx context.Context) error

Down rolls back the last migration

func (*CLIManager) LoadMigrations

func (cm *CLIManager) LoadMigrations() ([]Migration, error)

LoadMigrations loads all migration files from the migrations directory

func (*CLIManager) Reset

func (cm *CLIManager) Reset(ctx context.Context) error

Reset drops all tables and reapplies all migrations

func (*CLIManager) SetMigrationTableName

func (cm *CLIManager) SetMigrationTableName(tableName string) error

SetMigrationTableName sets the migration table name with validation

func (*CLIManager) Status

func (cm *CLIManager) Status(ctx context.Context) error

Status shows the status of all migrations

func (*CLIManager) Up

func (cm *CLIManager) Up(ctx context.Context) error

Up applies all pending migrations

func (*CLIManager) Validate

func (cm *CLIManager) Validate() error

Validate checks if all migration files are valid

type Migration

type Migration struct {
	Version     string     `json:"version"`
	Description string     `json:"description"`
	UpSQL       string     `json:"up_sql"`
	DownSQL     string     `json:"down_sql"`
	CreatedAt   time.Time  `json:"created_at"`
	AppliedAt   *time.Time `json:"applied_at,omitempty"`
	Checksum    string     `json:"checksum"`
}

Migration represents a database migration

type MigrationManager

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

MigrationManager manages database migrations

func NewMigrationManager

func NewMigrationManager(provider database.DatabaseProvider, logger *logrus.Logger) *MigrationManager

NewMigrationManager creates a new migration manager

func (*MigrationManager) ApplyMigration

func (mm *MigrationManager) ApplyMigration(ctx context.Context, migration Migration) error

ApplyMigration applies a migration

func (*MigrationManager) GetAppliedMigrations

func (mm *MigrationManager) GetAppliedMigrations(ctx context.Context) ([]Migration, error)

GetAppliedMigrations returns a list of applied migrations

func (*MigrationManager) GetMigrationStatus

func (mm *MigrationManager) GetMigrationStatus(ctx context.Context, availableMigrations []Migration) ([]MigrationStatus, error)

GetMigrationStatus returns the status of all migrations

func (*MigrationManager) Initialize

func (mm *MigrationManager) Initialize(ctx context.Context) error

Initialize creates the migration table if it doesn't exist

func (*MigrationManager) IsMigrationApplied

func (mm *MigrationManager) IsMigrationApplied(ctx context.Context, version string) (bool, error)

IsMigrationApplied checks if a migration is already applied

func (*MigrationManager) RollbackMigration

func (mm *MigrationManager) RollbackMigration(ctx context.Context, migration Migration) error

RollbackMigration rolls back a migration

func (*MigrationManager) SetTableName

func (mm *MigrationManager) SetTableName(table string) error

SetTableName sets the migration table name with validation

type MigrationStatus

type MigrationStatus struct {
	Migration Migration  `json:"migration"`
	Applied   bool       `json:"applied"`
	AppliedAt *time.Time `json:"applied_at,omitempty"`
}

MigrationStatus represents the status of a migration

Jump to

Keyboard shortcuts

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