migration

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MigrationsTableName is the name of the table that stores migration history
	MigrationsTableName = "redi_migrations"
)

Variables

This section is empty.

Functions

func ComputeChecksum

func ComputeChecksum(changes []types.SchemaChange) string

ComputeChecksum computes a checksum for a migration plan

func GenerateVersion

func GenerateVersion() string

GenerateVersion generates a new migration version based on timestamp

Types

type Differ

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

Differ compares schemas and generates migration plans

func NewDiffer

func NewDiffer(migrator types.DatabaseMigrator) *Differ

NewDiffer creates a new schema differ

func (*Differ) ComputeDiff

func (d *Differ) ComputeDiff(schemas map[string]*schema.Schema) ([]types.SchemaChange, error)

ComputeDiff compares desired schemas with current database state

type FileManager

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

FileManager handles migration files on disk

func NewFileManager

func NewFileManager(baseDir string) *FileManager

NewFileManager creates a new file manager

func (*FileManager) EnsureDirectory

func (f *FileManager) EnsureDirectory() error

EnsureDirectory ensures the migrations directory exists

func (*FileManager) GetPendingMigrations

func (f *FileManager) GetPendingMigrations(appliedVersions map[string]bool) ([]*types.MigrationFile, error)

GetPendingMigrations returns migrations that haven't been applied yet

func (*FileManager) ListMigrations

func (f *FileManager) ListMigrations() ([]*types.MigrationFile, error)

ListMigrations returns all migrations sorted by version

func (*FileManager) ReadMigration

func (f *FileManager) ReadMigration(version string) (*types.MigrationFile, error)

ReadMigration reads a migration from disk

func (*FileManager) WriteMigration

func (f *FileManager) WriteMigration(migration *types.MigrationFile) error

WriteMigration writes a migration to disk

type Generator

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

Generator generates migration files

func NewGenerator

func NewGenerator(migrator types.DatabaseMigrator, fileManager *FileManager) *Generator

NewGenerator creates a new migration generator

func (*Generator) GenerateMigration

func (g *Generator) GenerateMigration(name string, schemas map[string]*schema.Schema) (*types.MigrationFile, error)

GenerateMigration generates a new migration by comparing schemas with database

type HistoryManager

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

HistoryManager manages migration history in the database

func NewHistoryManager

func NewHistoryManager(db *sql.DB) *HistoryManager

NewHistoryManager creates a new history manager

func (*HistoryManager) EnsureMigrationTable

func (h *HistoryManager) EnsureMigrationTable() error

EnsureMigrationTable creates the migrations table if it doesn't exist

func (*HistoryManager) GetAppliedMigrations

func (h *HistoryManager) GetAppliedMigrations() ([]types.Migration, error)

GetAppliedMigrations returns all applied migrations

func (*HistoryManager) GetLastMigration

func (h *HistoryManager) GetLastMigration() (*types.Migration, error)

GetLastMigration returns the most recent migration

func (*HistoryManager) IsMigrationApplied

func (h *HistoryManager) IsMigrationApplied(version string) (bool, error)

IsMigrationApplied checks if a migration version has been applied

func (*HistoryManager) RecordMigration

func (h *HistoryManager) RecordMigration(version, name, checksum string) error

RecordMigration records a new migration in the history

func (*HistoryManager) RemoveMigration

func (h *HistoryManager) RemoveMigration(version string) error

RemoveMigration removes a migration from the history (for rollback)

type Manager

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

Manager coordinates the migration process

func NewManager

func NewManager(db types.Database, options types.MigrationOptions) (*Manager, error)

NewManager creates a new migration manager

func (*Manager) GenerateMigration

func (m *Manager) GenerateMigration(name string, schemas map[string]*schema.Schema) error

GenerateMigration generates a new migration file

func (*Manager) GetMigrationStatus

func (m *Manager) GetMigrationStatus() (*MigrationStatus, error)

GetMigrationStatus returns the current migration status

func (*Manager) Migrate

func (m *Manager) Migrate(schemas map[string]*schema.Schema) error

Migrate performs migration based on schemas and configured mode

func (*Manager) ResetMigrations

func (m *Manager) ResetMigrations() error

ResetMigrations drops all tables and clears migration history

func (*Manager) RollbackMigration

func (m *Manager) RollbackMigration() error

RollbackMigration rolls back the last applied migration

type MigrationStatus

type MigrationStatus struct {
	AppliedMigrations []types.Migration
	LastMigration     *types.Migration
	TableCount        int
	Tables            []string
}

MigrationStatus represents the current migration status

type Runner

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

Runner executes file-based migrations

func NewRunner

func NewRunner(db types.Database, fileManager *FileManager) (*Runner, error)

NewRunner creates a new migration runner

func (*Runner) RollbackMigration

func (r *Runner) RollbackMigration(ctx context.Context) error

RollbackMigration rolls back the last applied migration

func (*Runner) RunMigrations

func (r *Runner) RunMigrations(ctx context.Context) error

RunMigrations applies all pending migrations

Jump to

Keyboard shortcuts

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