migrations

package
v0.0.0-...-f2f1368 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migratable

type Migratable struct {
	ID   string
	Up   func(db *gorm.DB) error
	Down func(db *gorm.DB) error
}

Migratable contains information for applying and rolling back a migration.

type Migration

type Migration struct {
	ID        string `gorm:"type:varchar(255); primary_key; unique; column:id;"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `gorm:"index"`
}

Migration represnts the migration table.

type Migrator

type Migrator struct {
	DB                *gorm.DB
	Migrations        []Migratable
	InitialTables     []interface{}
	InitialJoinTables []string
}

Migrator encapsulates the migration list and operations.

func NewMigrator

func NewMigrator(db *gorm.DB) Migrator

NewMigrator creates a new migrator.

func (*Migrator) AddInitialJoinTables

func (migrator *Migrator) AddInitialJoinTables(models ...string)

AddInitialJoinTables add initial join tables. This is only useful during initial table roll back.

func (*Migrator) AddInitialTables

func (migrator *Migrator) AddInitialTables(models ...interface{})

AddInitialTables adds initial tables to the list.

func (*Migrator) AddMigration

func (migrator *Migrator) AddMigration(migration Migratable) error

AddMigration adds a new migration to migrator's list.

func (*Migrator) AddMigrations

func (migrator *Migrator) AddMigrations(migrations []Migratable) error

AddMigrations adds multiple migrations to migrator's list.

func (*Migrator) Down

func (migrator *Migrator) Down() error

Down rolls back the all migrations starting from the latest migration.

func (*Migrator) DownByOne

func (migrator *Migrator) DownByOne() error

DownByOne rolls back the next migration.

func (*Migrator) DownTo

func (migrator *Migrator) DownTo(id string) error

DownTo applies migrations down to the specified id starting from the latest migration.

func (*Migrator) PrepareMigrations

func (migrator *Migrator) PrepareMigrations(appKind string)

func (*Migrator) Up

func (migrator *Migrator) Up() error

Up applies the all migrations starting from the latest migration.

func (*Migrator) UpByOne

func (migrator *Migrator) UpByOne() error

UpByOne applies the next migration.

func (*Migrator) UpTo

func (migrator *Migrator) UpTo(id string) error

UpTo applies migrations up to the specified id starting from the latest migration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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