Help us shape the future of Go! Take the 2026 Go Developer Survey

migration

package
v1.20.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChangePatterns = []string{
	`_(to|from|in)_(\w+)_table$`,
	`_(to|from|in)_(\w+)$`,
}
View Source
var CreatePatterns = []string{
	`^create_(\w+)_table$`,
	`^create_(\w+)$`,
}

Functions

func Generate

func Generate(model any) (string, []string, error)

Generate creates migration schema lines from a model struct.

The model is read through the framework's own field annotations (database/internal/annotation.ParseAnnotation) and Go's type system, not through GORM's schema parser: the column name comes from `column:` or the snake_cased field name, the column type from the Go type with `type:` and `migration:` overriding it, and primary keys, indexes and the automatic timestamps from their annotations.

It returns the table name and the schema lines, in which the columns come first and the index and constraint definitions follow after an empty separator line.

Types

type Creator

type Creator struct {
}

func NewCreator

func NewCreator() *Creator

func (*Creator) GetFileName

func (r *Creator) GetFileName(name string) string

GetFileName Get the full path to the migration.

func (*Creator) GetPath

func (r *Creator) GetPath(name string) string

GetPath Get the full path to the migration.

func (*Creator) GetStub

func (r *Creator) GetStub(table string, create bool) string

GetStub Get the migration stub file.

func (*Creator) PopulateStub

func (r *Creator) PopulateStub(stub string, data StubData) (string, error)

PopulateStub Populate the place-holders in the migration stub.

type Migrator

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

func NewMigrator

func NewMigrator(artisan console.Artisan, schema contractsschema.Schema, table string) *Migrator

func (*Migrator) Create

func (r *Migrator) Create(name string, modelName string) (string, error)

func (*Migrator) Fresh

func (r *Migrator) Fresh() error

func (*Migrator) Reset

func (r *Migrator) Reset() error

func (*Migrator) Rollback

func (r *Migrator) Rollback(step, batch int) error

func (*Migrator) Run

func (r *Migrator) Run() error

func (*Migrator) Status

func (r *Migrator) Status() ([]contractsmigration.Status, error)

type Repository

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

func NewRepository

func NewRepository(schema schema.Schema, table string) *Repository

func (*Repository) CreateRepository

func (r *Repository) CreateRepository() error

func (*Repository) Delete

func (r *Repository) Delete(migration string) error

func (*Repository) DeleteRepository

func (r *Repository) DeleteRepository() error

func (*Repository) GetLast

func (r *Repository) GetLast() ([]migration.File, error)

func (*Repository) GetLastBatchNumber

func (r *Repository) GetLastBatchNumber() (int, error)

func (*Repository) GetMigrations

func (r *Repository) GetMigrations() ([]migration.File, error)

func (*Repository) GetMigrationsByBatch

func (r *Repository) GetMigrationsByBatch(batch int) ([]migration.File, error)

func (*Repository) GetMigrationsByStep

func (r *Repository) GetMigrationsByStep(steps int) ([]migration.File, error)

func (*Repository) GetNextBatchNumber

func (r *Repository) GetNextBatchNumber() (int, error)

func (*Repository) GetRan

func (r *Repository) GetRan() ([]string, error)

func (*Repository) Log

func (r *Repository) Log(file string, batch int) error

func (*Repository) RepositoryExists

func (r *Repository) RepositoryExists() bool

type StubData

type StubData struct {
	FacadesPackage string
	FacadesImport  string
	Package        string
	SchemaFields   []string
	Signature      string
	StructName     string
	Table          string
}

type Stubs

type Stubs struct {
}

func (Stubs) Create

func (receiver Stubs) Create() string

func (Stubs) Empty

func (receiver Stubs) Empty() string

func (Stubs) Update

func (receiver Stubs) Update() string

type TableGuesser

type TableGuesser struct {
}

func (TableGuesser) Guess

func (receiver TableGuesser) Guess(migration string) (string, bool)

Guess Attempt to guess the table name and "creation" status of the given migration, return table, create.

Jump to

Keyboard shortcuts

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