migrate

package
v0.4.23 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(
	pool *pgxpool.Pool,
	lg *zap.Logger,
	schema string,
	migrations ...fs.FS,
) error

Migrate Run migration. usual uses in service startup.

Types

type AddCheck added in v0.4.0

type AddCheck struct{ C *Check }

Check constraint changes

type AddColumn added in v0.4.0

type AddColumn struct{ C *Column }

Column-level changes

type AddExtension added in v0.4.0

type AddExtension struct{ E *Extension }

Extension changes

type AddForeignKey added in v0.4.0

type AddForeignKey struct{ FK *ForeignKey }

Foreign key changes

type AddFunction added in v0.4.0

type AddFunction struct{ F *Function }

Function changes

type AddIndex added in v0.4.0

type AddIndex struct{ I *Index }

Index changes

type AddPolicy added in v0.4.0

type AddPolicy struct {
	Table string
	P     *Policy
}

type AddSchema added in v0.4.0

type AddSchema struct{ S *Schema }

Schema-level changes

type AddTable added in v0.4.0

type AddTable struct{ T *Table }

Table-level changes

type AddTrigger added in v0.4.0

type AddTrigger struct {
	Table string
	T     *Trigger
}

Trigger changes

type Change added in v0.4.0

type Change interface {
	// contains filtered or unexported methods
}

Change represents a schema change.

type Check added in v0.4.0

type Check struct {
	Name      string
	Expr      string
	NoInherit bool
}

type Column added in v0.4.0

type Column struct {
	Name     string
	Type     string
	Nullable bool
	Default  string // raw SQL default expression
	Identity *Identity
	Comment  string
}

type Differ added in v0.4.0

type Differ interface {
	Diff(current, desired *SchemaState) ([]Change, error)
}

Differ compares two schema states and returns changes.

type DisableRLS added in v0.4.0

type DisableRLS struct{ Table string }

type DropCheck added in v0.4.0

type DropCheck struct{ C *Check }

type DropColumn added in v0.4.0

type DropColumn struct{ C *Column }

type DropExtension added in v0.4.0

type DropExtension struct{ E *Extension }

type DropForeignKey added in v0.4.0

type DropForeignKey struct{ FK *ForeignKey }

type DropFunction added in v0.4.0

type DropFunction struct{ F *Function }

type DropIndex added in v0.4.0

type DropIndex struct{ I *Index }

type DropPolicy added in v0.4.0

type DropPolicy struct {
	Table string
	P     *Policy
}

type DropSchema added in v0.4.0

type DropSchema struct{ S *Schema }

type DropTable added in v0.4.0

type DropTable struct{ T *Table }

type DropTrigger added in v0.4.0

type DropTrigger struct {
	Table string
	T     *Trigger
}

type EnableRLS added in v0.4.0

type EnableRLS struct{ Table string }

RLS changes

type Extension added in v0.4.0

type Extension struct {
	Name    string
	Schema  string
	Version string
}

type ForceRLS added in v0.4.0

type ForceRLS struct{ Table string }

type ForeignKey added in v0.4.0

type ForeignKey struct {
	Name       string
	Columns    []string
	RefTable   string
	RefSchema  string
	RefColumns []string
	OnUpdate   string
	OnDelete   string
}

type Function added in v0.4.0

type Function struct {
	Name       string
	Schema     string
	Args       []FunctionArg
	ReturnType string
	Language   string
	Body       string
	Volatility string
	Security   string
	Comment    string
}

type FunctionArg added in v0.4.0

type FunctionArg struct {
	Name    string
	Type    string
	Mode    string
	Default string
}

type Identity added in v0.4.0

type Identity struct {
	Generation string // "ALWAYS" or "BY DEFAULT"
	Start      int64
	Increment  int64
}

type Index added in v0.4.0

type Index struct {
	Name          string
	Columns       []IndexColumn
	Unique        bool
	Method        string // btree, hash, gin, gist, etc.
	Where         string // partial index predicate
	Include       []string
	NullsDistinct *bool
	Comment       string
}

type IndexColumn added in v0.4.0

type IndexColumn struct {
	Name  string
	Desc  bool
	Order string // ASC, DESC, or empty
}

type Inspector added in v0.4.0

type Inspector interface {
	InspectSchema(ctx context.Context, name string) (*Schema, error)
	InspectRealm(ctx context.Context) (*SchemaState, error)
}

Inspector inspects the current state of a database.

type Migrator added in v0.4.0

type Migrator interface {
	Inspector
	Differ
	Planner
	Lock(ctx context.Context, name string, timeout time.Duration) (unlock func() error, err error)
}

Migrator is the full migration engine interface.

type ModifyColumn added in v0.4.0

type ModifyColumn struct {
	From *Column
	To   *Column
}

type ModifyFunction added in v0.4.0

type ModifyFunction struct {
	From *Function
	To   *Function
}

type ModifyIndex added in v0.4.0

type ModifyIndex struct {
	From *Index
	To   *Index
}

type ModifyPolicy added in v0.4.0

type ModifyPolicy struct {
	Table string
	From  *Policy
	To    *Policy
}

type ModifyTable added in v0.4.0

type ModifyTable struct {
	From    *Table
	To      *Table
	Changes []Change
}

type ModifyTrigger added in v0.4.0

type ModifyTrigger struct {
	Table string
	From  *Trigger
	To    *Trigger
}

type Plan added in v0.4.0

type Plan struct {
	Name    string
	Changes []PlannedChange
}

Plan is a generated migration.

type PlannedChange added in v0.4.0

type PlannedChange struct {
	SQL     string // DDL statement
	Comment string // Human-readable description
	Reverse string // Rollback statement (if possible)
}

PlannedChange is a single DDL statement in a migration.

type Planner added in v0.4.0

type Planner interface {
	Plan(ctx context.Context, name string, changes []Change) (*Plan, error)
}

Planner generates SQL migration statements from changes.

type Policy added in v0.4.0

type Policy struct {
	Name       string
	Permissive bool
	Command    string
	Roles      []string
	Using      string
	WithCheck  string
}

type Schema added in v0.4.0

type Schema struct {
	Name       string
	Tables     []Table
	Extensions []Extension
	Functions  []Function
	Triggers   []Trigger // schema-level triggers
}

type SchemaState added in v0.4.0

type SchemaState struct {
	Schemas []Schema
}

SchemaState represents the full state of a database realm.

type Table added in v0.4.0

type Table struct {
	Name        string
	Schema      string
	Columns     []Column
	PrimaryKey  *Index
	Indexes     []Index
	ForeignKeys []ForeignKey
	Checks      []Check
	Policies    []Policy
	Triggers    []Trigger
	RLSEnabled  bool
	RLSForced   bool
	Comment     string
}

type Trigger added in v0.4.0

type Trigger struct {
	Name       string
	Table      string
	Events     []string
	Timing     string
	ForEachRow bool
	When       string
	Function   string
	Args       []string
	Comment    string
}

type UnforceRLS added in v0.4.0

type UnforceRLS struct{ Table string }

Jump to

Keyboard shortcuts

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