Documentation
¶
Index ¶
- func AutoMigrate(ctx context.Context, db *sqlx.DB, driverName string, ...) error
- func CreateMigration(dir, name string) error
- type AutoMigrateOptions
- type Config
- type DataMigration
- type DataMigrator
- type Manager
- func (m *Manager) Close() error
- func (m *Manager) ForceVersion(version uint) error
- func (m *Manager) GetVersion() (uint, bool, error)
- func (m *Manager) Init(ctx context.Context) error
- func (m *Manager) Rollback(ctx context.Context) error
- func (m *Manager) RollbackAll(ctx context.Context) error
- func (m *Manager) RunMigrations(ctx context.Context) error
- func (m *Manager) ValidateMigrations(ctx context.Context) error
- func (m *Manager) WithTransaction(ctx context.Context, fn func(*sql.Tx) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoMigrate ¶
func AutoMigrate(ctx context.Context, db *sqlx.DB, driverName string, options AutoMigrateOptions) error
AutoMigrate performs automatic database migration on startup
func CreateMigration ¶
CreateMigration creates a new migration file with the given name
Types ¶
type AutoMigrateOptions ¶
type AutoMigrateOptions struct {
// Whether to automatically run migrations on startup
Enabled bool
// Path to migration files
Path string
// Whether to fail startup if migrations fail
FailOnError bool
// Timeout for migration operations
Timeout time.Duration
// Whether to validate migrations without applying them
ValidateOnly bool
// Logger to use for migration messages
Logger *log.Logger
}
AutoMigrateOptions contains options for automatic migration
func DefaultOptions ¶
func DefaultOptions() AutoMigrateOptions
DefaultOptions returns the default migration options
type Config ¶
type Config struct {
// Path to migration files directory
MigrationsPath string `json:"migrations_path" yaml:"migrations_path"`
// Whether to automatically run migrations on startup
AutoMigrate bool `json:"auto_migrate" yaml:"auto_migrate"`
// Timeout for migration operations
MigrationTimeout time.Duration `json:"migration_timeout" yaml:"migration_timeout"`
// Whether to validate migrations without applying them
ValidateOnly bool `json:"validate_only" yaml:"validate_only"`
// Use a specific number of steps for migration (0 means all)
Steps int `json:"steps" yaml:"steps"`
}
Config holds the migration configuration
type DataMigration ¶
type DataMigration struct {
// Name is a descriptive name for the migration
Name string
// Version is the migration version number
Version uint
// Execute is the function that performs the data migration
Execute func(ctx context.Context, tx *sqlx.Tx) error
// Rollback is the function that reverts the data migration (optional)
Rollback func(ctx context.Context, tx *sqlx.Tx) error
}
DataMigration represents a migration that transforms data using Go code
type DataMigrator ¶
type DataMigrator struct {
// contains filtered or unexported fields
}
DataMigrator handles data migrations using Go code
func NewDataMigrator ¶
func NewDataMigrator(db *sqlx.DB, logger *log.Logger) *DataMigrator
NewDataMigrator creates a new data migrator
func (*DataMigrator) Register ¶
func (m *DataMigrator) Register(migration DataMigration)
Register adds a migration to the registry
func (*DataMigrator) RollbackMigration ¶
func (m *DataMigrator) RollbackMigration(ctx context.Context, version uint) error
RollbackMigration rolls back a specific data migration
func (*DataMigrator) RunMigration ¶
func (m *DataMigrator) RunMigration(ctx context.Context, version uint) error
RunMigration applies a specific data migration
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles database migrations
func NewManager ¶
NewManager creates a new migration manager
func (*Manager) ForceVersion ¶
ForceVersion forces the database to a specific version
func (*Manager) GetVersion ¶
GetVersion returns the current migration version
func (*Manager) RollbackAll ¶
RollbackAll rolls back all migrations
func (*Manager) RunMigrations ¶
RunMigrations applies all pending migrations
func (*Manager) ValidateMigrations ¶
ValidateMigrations checks if migrations are valid but doesn't apply them