db

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: GPL-2.0, GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusSuccess  = "success"
	StatusRollback = "rollback"
	StatusFailed   = "failed"
)

Status constants

Variables

This section is empty.

Functions

func GetDialector

func GetDialector(dialect, dsn string) (gorm.Dialector, error)

GetDialector returns the appropriate GORM dialector based on the dialect string

func LoadLocalMigrations

func LoadLocalMigrations(path string) (map[string]LocalMigration, error)

func RollbackMigrations

func RollbackMigrations(db *gorm.DB, cfg Config, steps int) error

RollbackMigrations runs down scripts in reverse order. Steps=0 means rollback all.

func RunMigrations

func RunMigrations(db *gorm.DB, cfg Config) error

RunMigrations is the main entry point

Types

type Config

type Config struct {
	TableName     string
	MigrationPath string
}

Config holds migration configuration

type LocalMigration

type LocalMigration struct {
	Version    string
	Name       string
	UpScript   string
	DownScript string
}

Helper struct for local files

type MigrationRecord

type MigrationRecord struct {
	ID         uint   `gorm:"primaryKey"`
	Version    string `gorm:"index"`
	Name       string
	UpScript   string `gorm:"type:text"`
	DownScript string `gorm:"type:text"`
	Status     string `gorm:"index"`
	AppliedAt  time.Time
	Message    string
}

MigrationRecord represents a migration record in the database

Jump to

Keyboard shortcuts

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