migrations

package
v0.19.765 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildIndexOptionsInterface

type BuildIndexOptionsInterface interface {
	BuildIndexOptions([]schema.IndexOption, *gorm.Statement) []interface{}
}

BuildIndexOptionsInterface build index options interface

type Index

type Index struct {
	Name    string
	Columns []string

	UniqueValue  sql.NullBool
	PrimaryValue sql.NullBool

	Option  string
	Type    string
	Comment string
}

type JoinTable

type JoinTable struct {
	Field     string
	JoinTable interface{}
}

type Migration

type Migration struct {
	Name      string
	Disabled  bool
	AlwaysRun bool

	Fn    func(context.Context, *gorm.DB) error
	SQL   string
	SQLFn func(context.Context, *gorm.DB) (string, error)
}

type MigrationErr

type MigrationErr struct {
	Model string
	Name  string
	Err   error
}

func (MigrationErr) Error

func (m MigrationErr) Error() string

func (MigrationErr) Unwrap

func (m MigrationErr) Unwrap() error

type MigrationModel

type MigrationModel struct {
	ID        string                `gorm:"primary_key;check:id_checker,char_length(id)=26" json:"id"`
	CreatedAt time.Time             `json:"created_at" gorm:"notnull"`
	UpdatedAt time.Time             `json:"updated_at" gorm:"notnull"`
	DeletedAt soft_delete.DeletedAt `json:"-"`

	Name   string          `json:"name" gorm:"unique"`
	Status MigrationStatus `json:"status" gorm:"not null;default null"`
}

func (*MigrationModel) BeforeCreate

func (a *MigrationModel) BeforeCreate(tx *gorm.DB) error

func (*MigrationModel) TableName

func (a *MigrationModel) TableName() string

type MigrationStatus

type MigrationStatus string
const (
	MigrationStatusApplied    MigrationStatus = "applied"
	MigrationStatusInProgress MigrationStatus = "in_progress"
	MigrationStatusError      MigrationStatus = "error"
)

type Migrator

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

func New

func New(params Params) *Migrator

func (*Migrator) Exec

func (m *Migrator) Exec(ctx context.Context) error

type Opts

type Opts struct {
	DropViewSQLTmpl   string
	CreateViewSQLTmpl string

	CreateIndexTmpl       string
	CreateUniqueIndexTmpl string
	CreatePKIndexTmpl     string
	DropIndexTmpl         string
}

func NewOpts

func NewOpts() *Opts

type Params

type Params struct {
	// Models
	Models     []any
	Migrations []Migration

	// Migrations DB is what is expected to have the migrations type registered
	MigrationsDB *gorm.DB

	TableOpts map[string]string
	Opts      *Opts

	// DB can be any gorm compatible db
	DB     *gorm.DB
	DBType string

	L   *zap.Logger
	Cfg *internal.Config
	MW  metrics.Writer
}

type View

type View struct {
	Name string

	SQL string
	DB  *gorm.DB

	// Controls whether a view is always reapplied (by dropping it and recreating it)
	AlwaysReapply bool
}

Jump to

Keyboard shortcuts

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