migrate

package
v0.0.0-...-0936e0e Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMigrationCanceled   = errors.New("rollback migration canceled")
	ErrEmptyPurpose        = errors.New("missing purpose when creating migration")
	ErrDuplicatedMigration = errors.New("migration exists")
	ErrNoMigration         = errors.New("running with no migration")
)
View Source
var MigrationTargetFolder string

MigrationTargetFolder is the migration folder target.

Functions

func BuildPlugin

func BuildPlugin(fileName string) (string, error)

func CreateConnection

func CreateConnection(c GormCliConfig) (string, error)

CreateConnection - Create the migration file with template.

func CreateMigration

func CreateMigration(purpose string) (string, error)

CreateMigration - Create the migration file with template.

func DownMigration

func DownMigration(db *gorm.DB, files []os.FileInfo, step int64) error

DownMigration - Rollback migration

func NewDB

func NewDB() *gorm.DB

NewDB get gorm DB instance.

func RemovePlugin

func RemovePlugin(goFileName string) error

func UpMigrate

func UpMigrate(db *gorm.DB, files []os.FileInfo) error

UpMigrate - Run migration

Types

type GormCliConfig

type GormCliConfig struct {
	DB struct {
		Dialects string
		Port     string
		Host     string
		User     string
		Password string
		Dbname   string
		Charset  string
		SSLMode  string
		TimeZone string
	}
	Migration struct {
		Path string
	}
}

GormCliConfig is the config for how gorm-cli connecting to DB

type GormMeta

type GormMeta struct {
	gorm.Model

	Name string `gorm:"type:varchar(255);primary_key"`
}

GormMeta - The meta for storing which migration has been executed.

type Migration

type Migration interface {
	Up(*gorm.DB) error
	Down(*gorm.DB) error
}

Migration - The main interface for migration files

Jump to

Keyboard shortcuts

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