migation

package
v0.10.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AddMigration        = "migrations"
	DeleteMigration     = "migrations"
	GetMigration        = "migrations"
	ListMigrationTables = "migrations/table"
	SetMigration        = "migrations/latest"
	UpdateMigration     = "migrations"
)

Variables

This section is empty.

Functions

func MigrationTablesToTable

func MigrationTablesToTable(mit []*MigrationTable)

MigrationTablesToTable returns a text table of all migrations for an env

func MigrationsToTable

func MigrationsToTable(mit SQLMigrationStrategy)

MigrationsToTable returns a text table for a given migration strategy

Types

type Migration

type Migration interface {
	// Add adds / registers a new migration
	Add(file string, env string, table string) error
	// Get returns the migration file
	Get(env string, table string) (*SQLMigrationStrategy, error)
	// ListTables lists the tables for a given env
	ListTables(env string) ([]*MigrationTable, error)
	// Delete removes a migration
	Delete(env string, table string, migrationID int) error
	// Update updates metadata associated with a migration
	Update(env string, table string, migrationID int, timeStamp time.Time, timeStampNull bool) error
	// Set defines the current latest migration
	Set(env string, table string, migrationID int) error
	// GetAll returns a all migrations for an env split by table
	GetAll(env string) ([]*SQLMigrationStrategy, error)
	// Run applies migrations
	Run(driver string, connection string, env string, table string) error
}

Migration represents the interface used to control migrations

func New

func New(url string) Migration

New creates a new migration container

type MigrationTable

type MigrationTable struct {
	Table      string          `json:"Table"`
	Migrations []*SQLMigration `json:"Migrations"`
}

MigrationTable defines the domain for all migrations associated with a table

type SQLMigration

type SQLMigration struct {
	Env            string     `json:"env"`
	FileID         string     `json:"file_id"`
	File           string     `json:"file"`
	FileOrder      int        `json:"file_order"`
	SourceTable    string     `json:"source_table"`
	MigratedAt     *time.Time `json:"migrated_at"`
	MigratedAtNull bool       `json:"migrated_at_null"`
	ID             int        `json:"id"`
	Script         string     `json:"script"`
	Status         *string    `json:"status"`
}

SQLMigration defines the domain for a migration

type SQLMigrationStrategy

type SQLMigrationStrategy struct {
	Table          string          `json:"source_table"`
	Env            string          `json:"env"`
	MigrationsUp   []*SQLMigration `json:"migrations_up"`
	MigrationsDown []*SQLMigration `json:"migrations_down"`
}

SQLMigrationStrategy defines the domain for a given table and env it includes our up and down migrations

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL