Documentation
¶
Index ¶
- Variables
- func ApplyMigration(config *MigratorConfig, migration *Migration) error
- func ApplyMigrations(config *MigratorConfig, migrationsToApply []*Migration) error
- func DryApplyMigrations(migrationsToApply []*Migration)
- func FillMigrationFiles(fsRepo FileRepo, config GeneratorConfig, migrations []*Migration) error
- func Generate(config GeneratorConfig) error
- func GenerateMigrationFiles(fsRepo FileRepo, migrations []*Migration) error
- func LoadMigrations(config *MigratorConfig, migrationType MigrationType) ([]*Migration, *Migration, error)
- func MigrationHistory(dbRepo DatabaseRepo) error
- func MigrationToFilename(migration *Migration) string
- func SelectExtention(database Database) string
- func SelectSubDirectory(database Database) string
- type Database
- type DatabaseRepo
- type FileRepo
- type GeneratorConfig
- type Migration
- func CalculateDownMigrationsToApply(lastMigration *Migration, migrations []*Migration, numberToMigrate int) []*Migration
- func CalculateUpMigrationsToApply(lastMigration *Migration, migrations []*Migration, numberToMigrate int) []*Migration
- func Clean(config *MigratorConfig) ([]*Migration, error)
- func GenerateNextMigrations(lastNumber int, name string, total int) []*Migration
- func MigrateDown(config *MigratorConfig) ([]*Migration, error)
- func MigrateUp(config *MigratorConfig) ([]*Migration, error)
- func ParseMigrationFromString(s string) (*Migration, error)
- type MigrationType
- type MigratorConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidFormat = errors.New("invalid_format") ErrParsingMigrationType = errors.New("invalid_migration_type") ErrReadingFileNames = errors.New("error_reading_file_names") ErrParsingMigrations = errors.New("error_parsing_migrations") ErrCreatingMigrationFile = errors.New("error_creating_migration_file") ErrNoMigrationsToApply = errors.New("error_no_migrations_to_apply") ErrReadingLastAppliedMigration = errors.New("error_reading_last_applied_migration") // Storage ErrLoadingMigrations = errors.New("error_loading_migrations") ErrMigrationTableDoesNotExist = errors.New("error_migration_table_does_not_exist") ErrDatabaseNotInitialized = errors.New("error_database_not_initialized") )
Functions ¶
func ApplyMigration ¶
func ApplyMigration(config *MigratorConfig, migration *Migration) error
TODO: apply all as one transaction ?. if one fails, rollback all
func ApplyMigrations ¶
func ApplyMigrations(config *MigratorConfig, migrationsToApply []*Migration) error
func DryApplyMigrations ¶ added in v0.6.1
func DryApplyMigrations(migrationsToApply []*Migration)
func FillMigrationFiles ¶
func FillMigrationFiles(fsRepo FileRepo, config GeneratorConfig, migrations []*Migration) error
func Generate ¶
func Generate(config GeneratorConfig) error
func GenerateMigrationFiles ¶
func LoadMigrations ¶
func LoadMigrations(config *MigratorConfig, migrationType MigrationType) ([]*Migration, *Migration, error)
func MigrationHistory ¶
func MigrationHistory(dbRepo DatabaseRepo) error
func MigrationToFilename ¶
func SelectExtention ¶
func SelectSubDirectory ¶
Types ¶
type DatabaseRepo ¶
type DatabaseRepo interface {
// Load last applied migration entry from the migration table
// - Creates migration table if not exists
// - Returns nil if no entry found
LoadLastAppliedMigration() (*Migration, error)
// Load all migration entries from the migration table
LoadMigrations() ([]*Migration, error)
// Create a migration table if not exists
CreateMigrationTableIfNotExists() error
// Get the last applied migration from the migration table
GetLastAppliedMigration() (*Migration, error)
// Apply a migration to the database and add an entry to the migration table
ApplyMigration(migration *Migration) error
// Delete the migration table
DeleteMigrationTable() error
}
type FileRepo ¶
type FileRepo interface {
// Create a migration directory if not exists
OpenDirectory() error
// Load migrations from directoryy
LoadMigrationsFromFile(migrationType MigrationType) ([]*Migration, error)
// Read all the files from the migration directory
GetMigrationFilePathsByType(migrationType MigrationType) ([]string, error)
// Create a migration file
CreateMigrationFile(migration *Migration) error
// Write to File
WriteMigrationToFile(migration *Migration) error
// Read Query from File
LoadMigrationQuery(migration *Migration) error
// Delete a migration file
DeleteMigrationFile(migration *Migration) error
// Delete the migration directory
DeleteMigrationDirectory() error
}
type GeneratorConfig ¶
type Migration ¶
type Migration struct {
Number int
Name string
Type MigrationType
Path string
Query string
Created time.Time
}
func CalculateDownMigrationsToApply ¶
func CalculateDownMigrationsToApply(lastMigration *Migration, migrations []*Migration, numberToMigrate int) []*Migration
It will accept a reversed list of migrations
func Clean ¶
func Clean(config *MigratorConfig) ([]*Migration, error)
func GenerateNextMigrations ¶
func MigrateDown ¶
func MigrateDown(config *MigratorConfig) ([]*Migration, error)
func MigrateUp ¶
func MigrateUp(config *MigratorConfig) ([]*Migration, error)
type MigrationType ¶
type MigrationType string
const ( MigrationUp MigrationType = "up" MigrationDown MigrationType = "down" )
type MigratorConfig ¶
type MigratorConfig struct {
NumToMigrate int
DryRun bool
DBRepo DatabaseRepo
FSRepo FileRepo
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.