migrations

package
v0.19.1302 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

	Concurrently bool
}

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"`

	// why the migration failed, so the reason survives even when logging does not
	Error string `json:"error,omitempty" gorm:"type:text;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

	CreateIndexConcurrentlyTmpl       string
	CreateUniqueIndexConcurrentlyTmpl string
	DropIndexConcurrentlyTmpl         string
	InvalidIndexSQL                   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