Documentation
¶
Index ¶
- Constants
- func ComputeChecksum(changes []types.SchemaChange) string
- func GenerateVersion() string
- type Differ
- type FileManager
- func (f *FileManager) EnsureDirectory() error
- func (f *FileManager) GetPendingMigrations(appliedVersions map[string]bool) ([]*types.MigrationFile, error)
- func (f *FileManager) ListMigrations() ([]*types.MigrationFile, error)
- func (f *FileManager) ReadMigration(version string) (*types.MigrationFile, error)
- func (f *FileManager) WriteMigration(migration *types.MigrationFile) error
- type Generator
- type HistoryManager
- func (h *HistoryManager) EnsureMigrationTable() error
- func (h *HistoryManager) GetAppliedMigrations() ([]types.Migration, error)
- func (h *HistoryManager) GetLastMigration() (*types.Migration, error)
- func (h *HistoryManager) IsMigrationApplied(version string) (bool, error)
- func (h *HistoryManager) RecordMigration(version, name, checksum string) error
- func (h *HistoryManager) RemoveMigration(version string) error
- type Manager
- func (m *Manager) GenerateMigration(name string, schemas map[string]*schema.Schema) error
- func (m *Manager) GetMigrationStatus() (*MigrationStatus, error)
- func (m *Manager) Migrate(schemas map[string]*schema.Schema) error
- func (m *Manager) ResetMigrations() error
- func (m *Manager) RollbackMigration() error
- type MigrationStatus
- type Runner
Constants ¶
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 ¶
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 ¶
NewManager creates a new migration manager
func (*Manager) GenerateMigration ¶
GenerateMigration generates a new migration file
func (*Manager) GetMigrationStatus ¶
func (m *Manager) GetMigrationStatus() (*MigrationStatus, error)
GetMigrationStatus returns the current migration status
func (*Manager) ResetMigrations ¶
ResetMigrations drops all tables and clears migration history
func (*Manager) RollbackMigration ¶
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 ¶
RollbackMigration rolls back the last applied migration