migrations

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Migrations = NewMigrations()

Migrations Globally available

Functions

func DropAllTable

func DropAllTable(db *gorm.DB, tables []string) error

func InitMigrationTable

func InitMigrationTable(db *gorm.DB)

func ListTable

func ListTable(db *gorm.DB) (tables []string)

Types

type ConfigFunc

type ConfigFunc func(*Migrator)

func WithConnection

func WithConnection(name string) ConfigFunc

func WithFolder

func WithFolder(name string) ConfigFunc

type MigrationItem

type MigrationItem struct {
	Name string
	Up   func(db *gorm.DB)
	Down func(db *gorm.DB)
}

type MigrationList

type MigrationList struct {
	Items []*MigrationItem
}

func NewMigrations

func NewMigrations() *MigrationList

func (*MigrationList) Register

func (m *MigrationList) Register(name string, up func(db *gorm.DB), down func(db *gorm.DB)) error

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

func NewMigrator

func NewMigrator(db *database.Database, migrationsList *MigrationList, configs ...ConfigFunc) *Migrator

NewMigrator creates a new migrator instance, it requires a database connection and a list of migrations If no migrations list is provided, a new empty list will be created If no connection is provided, the default connection will be used, use WithConnection to set a custom connection

func (*Migrator) Down

func (m *Migrator) Down() error

Down rollback (down) all migrations that has been run in the last batch

func (*Migrator) Fresh

func (m *Migrator) Fresh() error

func (*Migrator) Migrations

func (m *Migrator) Migrations() *MigrationList

func (*Migrator) NewMigration

func (m *Migrator) NewMigration(name *string) error

func (*Migrator) Up

func (m *Migrator) Up() error

Up runs all migrations that has not been run yet

Jump to

Keyboard shortcuts

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