Documentation
¶
Index ¶
- type Config
- type DatabaseDriver
- type Manager
- func (m *Manager) CreateMigration(name string) error
- func (m *Manager) GetAppliedMigrations() ([]*Migration, error)
- func (m *Manager) GetCurrentVersion() (int64, error)
- func (m *Manager) GetMigrationsDir() string
- func (m *Manager) GetPendingMigrations() ([]*Migration, error)
- func (m *Manager) GetStatus() ([]*Migration, error)
- func (m *Manager) LoadMigrations() ([]*Migration, error)
- func (m *Manager) Log(msg string, c *color.Color)
- func (m *Manager) LogError(msg string)
- func (m *Manager) LogInfo(msg string)
- func (m *Manager) LogSuccess(msg string)
- func (m *Manager) MigrateDown(targetVersion int64, count int) error
- func (m *Manager) MigrateUp(targetVersion int64, count int) error
- type Migration
- type MigrationTracker
- type MongoDriver
- func (m *MongoDriver) Close() error
- func (m *MongoDriver) ExecuteMigration(migrationFile string, isUp bool) error
- func (m *MongoDriver) GetAppliedMigrations() ([]int64, error)
- func (m *MongoDriver) GetCurrentVersion() (int64, error)
- func (m *MongoDriver) GetDBType() string
- func (m *MongoDriver) Initialize() error
- func (m *MongoDriver) MarkMigrationApplied(version int64) error
- func (m *MongoDriver) MarkMigrationReverted(version int64) error
- type PostgresDriver
- func (p *PostgresDriver) Close() error
- func (p *PostgresDriver) ExecuteMigration(migrationFile string, isUp bool) error
- func (p *PostgresDriver) GetAppliedMigrations() ([]int64, error)
- func (p *PostgresDriver) GetCurrentVersion() (int64, error)
- func (p *PostgresDriver) GetDBType() string
- func (p *PostgresDriver) Initialize() error
- func (p *PostgresDriver) MarkMigrationApplied(version int64) error
- func (p *PostgresDriver) MarkMigrationReverted(version int64) error
- type SchemaMigration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatabaseDriver ¶
type DatabaseDriver interface {
MigrationTracker
// ExecuteMigration executes a migration file
ExecuteMigration(migrationFile string, isUp bool) error
// GetDBType returns the database type (postgres, mongo)
GetDBType() string
}
DatabaseDriver defines the interface for database-specific operations
type Manager ¶
type Manager struct {
Driver DatabaseDriver
Config *Config
}
Manager handles migration operations
func NewManager ¶
func NewManager(driver DatabaseDriver, config *Config) *Manager
NewManager creates a new migration manager
func (*Manager) CreateMigration ¶
CreateMigration creates new migration files
func (*Manager) GetAppliedMigrations ¶
GetAppliedMigrations returns migrations that have been applied
func (*Manager) GetCurrentVersion ¶
GetCurrentVersion returns the current migration version
func (*Manager) GetMigrationsDir ¶
GetMigrationsDir returns the migrations directory for the current database type
func (*Manager) GetPendingMigrations ¶
GetPendingMigrations returns migrations that haven't been applied
func (*Manager) LoadMigrations ¶
LoadMigrations loads all migration files from the migrations directory
func (*Manager) LogSuccess ¶
LogSuccess prints a success message in green
func (*Manager) MigrateDown ¶
MigrateDown reverts applied migrations
type Migration ¶
type Migration struct {
Version int64
Name string
UpFile string
DownFile string
Applied bool
AppliedAt *time.Time
}
Migration represents a single migration file
type MigrationTracker ¶
type MigrationTracker interface {
// Initialize creates the tracking table/collection if it doesn't exist
Initialize() error
// GetAppliedMigrations returns all applied migration versions
GetAppliedMigrations() ([]int64, error)
// MarkMigrationApplied marks a migration as applied
MarkMigrationApplied(version int64) error
// MarkMigrationReverted removes a migration from applied list
MarkMigrationReverted(version int64) error
// GetCurrentVersion returns the latest applied migration version
GetCurrentVersion() (int64, error)
// Close closes the database connection
Close() error
}
MigrationTracker defines the interface for tracking applied migrations
type MongoDriver ¶
type MongoDriver struct {
// contains filtered or unexported fields
}
MongoDriver implements DatabaseDriver for MongoDB
func NewMongoDriver ¶
func NewMongoDriver() (*MongoDriver, error)
NewMongoDriver creates a new MongoDB driver
func (*MongoDriver) ExecuteMigration ¶
func (m *MongoDriver) ExecuteMigration(migrationFile string, isUp bool) error
ExecuteMigration executes a migration file using mongosh
func (*MongoDriver) GetAppliedMigrations ¶
func (m *MongoDriver) GetAppliedMigrations() ([]int64, error)
GetAppliedMigrations returns all applied migration versions
func (*MongoDriver) GetCurrentVersion ¶
func (m *MongoDriver) GetCurrentVersion() (int64, error)
GetCurrentVersion returns the latest applied migration version
func (*MongoDriver) GetDBType ¶
func (m *MongoDriver) GetDBType() string
GetDBType returns the database type
func (*MongoDriver) Initialize ¶
func (m *MongoDriver) Initialize() error
Initialize creates the schema_migrations collection if it doesn't exist
func (*MongoDriver) MarkMigrationApplied ¶
func (m *MongoDriver) MarkMigrationApplied(version int64) error
MarkMigrationApplied marks a migration as applied
func (*MongoDriver) MarkMigrationReverted ¶
func (m *MongoDriver) MarkMigrationReverted(version int64) error
MarkMigrationReverted removes a migration from applied list
type PostgresDriver ¶
type PostgresDriver struct {
// contains filtered or unexported fields
}
PostgresDriver implements DatabaseDriver for PostgreSQL
func NewPostgresDriver ¶
func NewPostgresDriver() (*PostgresDriver, error)
NewPostgresDriver creates a new PostgreSQL driver
func (*PostgresDriver) Close ¶
func (p *PostgresDriver) Close() error
Close closes the database connection
func (*PostgresDriver) ExecuteMigration ¶
func (p *PostgresDriver) ExecuteMigration(migrationFile string, isUp bool) error
ExecuteMigration executes a migration file
func (*PostgresDriver) GetAppliedMigrations ¶
func (p *PostgresDriver) GetAppliedMigrations() ([]int64, error)
GetAppliedMigrations returns all applied migration versions
func (*PostgresDriver) GetCurrentVersion ¶
func (p *PostgresDriver) GetCurrentVersion() (int64, error)
GetCurrentVersion returns the latest applied migration version
func (*PostgresDriver) GetDBType ¶
func (p *PostgresDriver) GetDBType() string
GetDBType returns the database type
func (*PostgresDriver) Initialize ¶
func (p *PostgresDriver) Initialize() error
Initialize creates the schema_migrations table if it doesn't exist
func (*PostgresDriver) MarkMigrationApplied ¶
func (p *PostgresDriver) MarkMigrationApplied(version int64) error
MarkMigrationApplied marks a migration as applied
func (*PostgresDriver) MarkMigrationReverted ¶
func (p *PostgresDriver) MarkMigrationReverted(version int64) error
MarkMigrationReverted removes a migration from applied list
type SchemaMigration ¶
type SchemaMigration struct {
Version int64 `bson:"version"`
AppliedAt time.Time `bson:"applied_at"`
}
SchemaMigration represents a document in the schema_migrations collection