Documentation
¶
Overview ¶
Package migrations defines constants and status values for DynamORM database migration management.
Index ¶
- Constants
- func MustRegister(migration Migration)
- func Register(migration Migration) error
- type BaseMigration
- type ExampleAddUserLookupIndex
- type ExampleDependentMigration
- type GSIDefinition
- type GSIHelper
- func (h *GSIHelper) CreateGSI(ctx context.Context, gsi GSIDefinition) error
- func (h *GSIHelper) DeleteGSI(ctx context.Context, gsiName string) error
- func (h *GSIHelper) GetGSIStatus(ctx context.Context, gsiName string) (*GSIMigrationRecord, error)
- func (h *GSIHelper) ListGSIMigrations(ctx context.Context) ([]*GSIMigrationRecord, error)
- type GSIMigration
- type GSIMigrationRecord
- type MigrateOptions
- type Migration
- type MigrationHistory
- type MigrationStatus
- type Migrator
- func (m *Migrator) GetAppliedMigrations(_ context.Context) (map[string]bool, error)
- func (m *Migrator) GetMigrationHistory(_ context.Context) ([]*MigrationHistory, error)
- func (m *Migrator) GetMigrationStatus(_ context.Context) (*MigrationStatus, error)
- func (m *Migrator) GetPendingMigrations(ctx context.Context) ([]Migration, error)
- func (m *Migrator) GetRollbackPlan(ctx context.Context, opts RollbackOptions) ([]*MigrationHistory, error)
- func (m *Migrator) Migrate(ctx context.Context, opts MigrateOptions) error
- func (m *Migrator) MigrateDown(ctx context.Context, target string) error
- func (m *Migrator) Rollback(ctx context.Context) error
- func (m *Migrator) RollbackLast(ctx context.Context) error
- func (m *Migrator) RollbackSteps(ctx context.Context, steps int) error
- func (m *Migrator) RollbackTo(ctx context.Context, targetID string) error
- func (m *Migrator) RollbackWithOptions(ctx context.Context, opts RollbackOptions) error
- func (m *Migrator) Run(ctx context.Context) error
- func (m *Migrator) UpdateMigrationStatus(_ context.Context, status *MigrationStatus) error
- type Registry
- func (r *Registry) All() []Migration
- func (r *Registry) Get(id string) (Migration, bool)
- func (r *Registry) GetInOrder(migrations []Migration) ([]Migration, error)
- func (r *Registry) GetPending(appliedMigrations map[string]bool) []Migration
- func (r *Registry) MustRegister(migration Migration)
- func (r *Registry) Register(migration Migration) error
- func (r *Registry) ValidateDependencies(migration Migration, appliedMigrations map[string]bool) error
- type RollbackOptions
- type ValidationError
- type ValidationResult
- type ValidationWarning
- type Validator
Constants ¶
const ( StatusActive = "ACTIVE" StatusCurrent = "CURRENT" StatusApplied = "applied" StatusRolledBack = "rolled_back" StatusPending = "pending" )
Migration status constants
const ( EventInsert = "INSERT" EventModify = "MODIFY" EventRemove = "REMOVE" )
Event type constants
const (
MigrationStatusKey = "MIGRATION#STATUS"
)
Migration-related constants
Variables ¶
This section is empty.
Functions ¶
func MustRegister ¶
func MustRegister(migration Migration)
MustRegister registers a migration to the global registry and panics on error
Types ¶
type BaseMigration ¶
type BaseMigration struct {
// contains filtered or unexported fields
}
BaseMigration provides common functionality for migrations
func NewBaseMigration ¶
func NewBaseMigration(id string, version int64, description string, dependencies ...string) BaseMigration
NewBaseMigration creates a new base migration
func (BaseMigration) Dependencies ¶
func (m BaseMigration) Dependencies() []string
Dependencies returns the migration dependencies
func (BaseMigration) Description ¶
func (m BaseMigration) Description() string
Description returns the migration description
func (BaseMigration) Version ¶
func (m BaseMigration) Version() int64
Version returns the migration version
type ExampleAddUserLookupIndex ¶
type ExampleAddUserLookupIndex struct {
BaseMigration
}
ExampleAddUserLookupIndex demonstrates how to create custom migrations
func NewExampleAddUserLookupIndex ¶
func NewExampleAddUserLookupIndex() *ExampleAddUserLookupIndex
NewExampleAddUserLookupIndex creates an example migration
type ExampleDependentMigration ¶
type ExampleDependentMigration struct {
BaseMigration
}
ExampleDependentMigration demonstrates a migration with dependencies
func NewExampleDependentMigration ¶
func NewExampleDependentMigration() *ExampleDependentMigration
NewExampleDependentMigration creates a new example dependent migration
type GSIDefinition ¶
type GSIDefinition struct {
Name string
HashKey string
HashKeyType string // "S", "N", "B"
RangeKey string
RangeKeyType string // "S", "N", "B"
ProjectionType string // "ALL", "KEYS_ONLY", "INCLUDE"
IncludeFields []string
ReadCapacity int64
WriteCapacity int64
}
GSIDefinition defines a Global Secondary Index
type GSIHelper ¶
type GSIHelper struct {
// contains filtered or unexported fields
}
GSIHelper provides utilities for managing Global Secondary Indexes using DynamORM
func NewGSIHelper ¶
NewGSIHelper creates a new GSI helper using DynamORM
func (*GSIHelper) CreateGSI ¶
func (h *GSIHelper) CreateGSI(ctx context.Context, gsi GSIDefinition) error
CreateGSI creates a new Global Secondary Index using DynamORM patterns
func (*GSIHelper) GetGSIStatus ¶
GetGSIStatus retrieves the status of a GSI migration
func (*GSIHelper) ListGSIMigrations ¶
func (h *GSIHelper) ListGSIMigrations(ctx context.Context) ([]*GSIMigrationRecord, error)
ListGSIMigrations lists all GSI migration records
type GSIMigration ¶
type GSIMigration struct {
BaseMigration
TableName string
GSI GSIDefinition
}
GSIMigration is a helper base for GSI-related migrations
func NewGSIMigration ¶
func NewGSIMigration(id string, version int64, description string, tableName string, gsi GSIDefinition, dependencies ...string) GSIMigration
NewGSIMigration creates a new GSI migration
type GSIMigrationRecord ¶
type GSIMigrationRecord struct {
PK string `theorydb:"pk"`
SK string `theorydb:"sk"`
TableName string `json:"table_name"`
GSIName string `json:"gsi_name"`
HashKey string `json:"hash_key"`
HashKeyType string `json:"hash_key_type"`
RangeKey string `json:"range_key,omitempty"`
RangeKeyType string `json:"range_key_type,omitempty"`
ProjectionType string `json:"projection_type"`
IncludeFields []string `json:"include_fields,omitempty"`
ReadCapacity int64 `json:"read_capacity"`
WriteCapacity int64 `json:"write_capacity"`
Status string `json:"status"` // CREATED, DELETED, FAILED
CreatedAt time.Time `json:"created_at"`
Error string `json:"error,omitempty"`
}
GSIMigrationRecord tracks GSI migration operations
type MigrateOptions ¶
type MigrateOptions struct {
// DryRun if true, will only log what would be done without executing
DryRun bool
// Target specific migration ID to migrate up to (inclusive)
Target string
// Force allows running migrations even if there are validation warnings
Force bool
}
MigrateOptions contains options for running migrations
type Migration ¶
type Migration interface {
// ID returns a unique identifier for this migration (e.g., "20240101_add_user_index")
ID() string
// Version returns the version number for ordering (e.g., 20240101120000)
Version() int64
// Description returns a human-readable description of what this migration does
Description() string
// Up applies the migration
Up(ctx context.Context, db core.DB) error
// Down reverses the migration
Down(ctx context.Context, db core.DB) error
// Dependencies returns a list of migration IDs that must be applied before this one
Dependencies() []string
}
Migration represents a database schema change
func NewExampleGSIMigration ¶
func NewExampleGSIMigration() Migration
NewExampleGSIMigration creates an example GSI migration
type MigrationHistory ¶
type MigrationHistory struct {
PK string `theorydb:"pk"`
SK string `theorydb:"sk"`
ID string `theorydb:"id"`
Version int64 `theorydb:"version"`
Description string `theorydb:"description"`
AppliedAt time.Time `theorydb:"applied_at"`
AppliedBy string `theorydb:"applied_by"`
Checksum string `theorydb:"checksum"`
Status string `theorydb:"status"` // "applied", "failed", "rolled_back"
Error string `theorydb:"error,omitempty"`
}
MigrationHistory represents a record of an applied migration
func (*MigrationHistory) GetTableKeys ¶
func (m *MigrationHistory) GetTableKeys() (string, string)
GetTableKeys returns the primary key values for DynamoDB
type MigrationStatus ¶
type MigrationStatus struct {
PK string `theorydb:"pk"`
SK string `theorydb:"sk"`
LastMigrationID string `theorydb:"last_migration_id"`
LastVersion int64 `theorydb:"last_version"`
UpdatedAt time.Time `theorydb:"updated_at"`
IsLocked bool `theorydb:"is_locked"`
LockedBy string `theorydb:"locked_by,omitempty"`
LockedAt time.Time `theorydb:"locked_at,omitempty"`
}
MigrationStatus represents the current state of migrations
func (*MigrationStatus) GetTableKeys ¶
func (m *MigrationStatus) GetTableKeys() (string, string)
GetTableKeys returns the primary key values for DynamoDB
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator handles migration execution and tracking
func NewMigrator ¶
NewMigrator creates a new migrator instance
func (*Migrator) GetAppliedMigrations ¶
GetAppliedMigrations returns a map of applied migration IDs
func (*Migrator) GetMigrationHistory ¶
func (m *Migrator) GetMigrationHistory(_ context.Context) ([]*MigrationHistory, error)
GetMigrationHistory returns the migration history
func (*Migrator) GetMigrationStatus ¶
func (m *Migrator) GetMigrationStatus(_ context.Context) (*MigrationStatus, error)
GetMigrationStatus returns the current migration status
func (*Migrator) GetPendingMigrations ¶
GetPendingMigrations returns a list of migrations that haven't been applied
func (*Migrator) GetRollbackPlan ¶
func (m *Migrator) GetRollbackPlan(ctx context.Context, opts RollbackOptions) ([]*MigrationHistory, error)
GetRollbackPlan returns the migrations that would be rolled back
func (*Migrator) Migrate ¶
func (m *Migrator) Migrate(ctx context.Context, opts MigrateOptions) error
Migrate runs all pending migrations up to the target (or all if target is empty)
func (*Migrator) MigrateDown ¶
MigrateDown rolls back migrations down to a target version
func (*Migrator) RollbackLast ¶
RollbackLast rolls back the most recent migration
func (*Migrator) RollbackSteps ¶
RollbackSteps rolls back the specified number of migrations
func (*Migrator) RollbackTo ¶
RollbackTo rolls back all migrations after the target (target remains applied)
func (*Migrator) RollbackWithOptions ¶
func (m *Migrator) RollbackWithOptions(ctx context.Context, opts RollbackOptions) error
RollbackWithOptions reverses applied migrations with specified options
func (*Migrator) UpdateMigrationStatus ¶
func (m *Migrator) UpdateMigrationStatus(_ context.Context, status *MigrationStatus) error
UpdateMigrationStatus updates the overall migration status
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages available migrations
func (*Registry) GetInOrder ¶
GetInOrder returns migrations in dependency order
func (*Registry) GetPending ¶
GetPending returns migrations that haven't been applied yet
func (*Registry) MustRegister ¶
MustRegister registers a migration and panics on error
type RollbackOptions ¶
type RollbackOptions struct {
// DryRun if true, will only log what would be done without executing
DryRun bool
// Target specific migration ID to rollback to (exclusive)
Target string
// Steps number of migrations to rollback (ignored if Target is set)
Steps int
// Force allows rollback even if there are dependency conflicts
Force bool
}
RollbackOptions contains options for rolling back migrations
type ValidationError ¶
ValidationError represents a validation error that prevents migration
type ValidationResult ¶
type ValidationResult struct {
Valid bool
Errors []ValidationError
Warnings []ValidationWarning
}
ValidationResult contains the results of migration validation
func (*ValidationResult) Format ¶
func (r *ValidationResult) Format() string
Format formats validation results for display
type ValidationWarning ¶
ValidationWarning represents a validation warning that doesn't prevent migration
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator validates migrations before execution
func NewValidator ¶
NewValidator creates a new migration validator
func (*Validator) ValidateAll ¶
func (v *Validator) ValidateAll(ctx context.Context) (*ValidationResult, error)
ValidateAll validates all pending migrations
func (*Validator) ValidateMigration ¶
func (v *Validator) ValidateMigration(ctx context.Context, migrationID string) (*ValidationResult, error)
ValidateMigration validates a specific migration
func (*Validator) ValidateRollback ¶
func (v *Validator) ValidateRollback(ctx context.Context, opts RollbackOptions) (*ValidationResult, error)
ValidateRollback validates that a rollback can be safely performed