migrator

package
v0.0.0-...-1e676ae Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package migrator is the manager of db migrations

Index

Constants

View Source
const (
	// GormMode gorm mode
	GormMode string = "gorm"
	// SqlMode sql mode
	SqlMode string = "sql"
)

Variables

This section is empty.

Functions

func Create

func Create(name, mode string) error

Create generate one migration template file to use

func GetDownSQLKey

func GetDownSQLKey(migrationName string) string

GetDownSQLKey get the up sql key for MigrationSQLs

func GetUpSQLKey

func GetUpSQLKey(migrationName string) string

GetUpSQLKey get the down sql key for MigrationSQLs

func NewDB

func NewDB(debug bool) (*gorm.DB, error)

NewDB new a gorm db instance

Types

type Migration

type Migration struct {
	Version string
	Name    string
	Mode    string
	Up      func(*gorm.DB) error
	Down    func(*gorm.DB) error
	// contains filtered or unexported fields
}

Migration is one specific db migration

type Migrator

type Migrator struct {
	Versions      []string
	Migrations    map[string]*Migration
	MigrationSQLs map[string]string
	// contains filtered or unexported fields
}

Migrator is the controller for all migrations

func GetMigrator

func GetMigrator() *Migrator

GetMigrator get the migrator

func Init

func Init(db *gorm.DB) (*Migrator, error)

Init create the db connection and get migrator

func (*Migrator) AddMigration

func (m *Migrator) AddMigration(mg *Migration)

AddMigration add one migration to migrator

func (*Migrator) Down

func (m *Migrator) Down(step int) error

Down execute backward migration

func (*Migrator) MigrationStatus

func (m *Migrator) MigrationStatus() error

MigrationStatus get the current migration status

func (*Migrator) Up

func (m *Migrator) Up(step int) error

Up execute forward migration

Jump to

Keyboard shortcuts

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