package schema
import "ariga.io/atlas/sql/schema"
Index ¶
- Constants
- Variables
- func IsNotExistError(err error) bool
- func IsType(t1, t2 Type) bool
- func ReplaceOrAppend(attrs *[]Attr, v Attr)
- func SortRefs(refs []Object)
- type AddAttr
- type AddCheck
- type AddColumn
- type AddForeignKey
- type AddFunc
- type AddIndex
- type AddObject
- type AddPrimaryKey
- type AddProc
- type AddSchema
- type AddTable
- type AddTrigger
- type AddView
- type Attr
- type BinaryOption
- type BinaryType
- type BoolType
- type Change
- type ChangeKind
- type Changes
- func (c Changes) IndexAddColumn(name string) int
- func (c Changes) IndexAddIndex(name string) int
- func (c Changes) IndexAddTable(name string) int
- func (c Changes) IndexDropColumn(name string) int
- func (c Changes) IndexDropIndex(name string) int
- func (c Changes) IndexDropTable(name string) int
- func (c Changes) IndexModifyColumn(name string) int
- func (c Changes) LastIndexAddTable(name string) int
- func (c Changes) LastIndexDropTable(name string) int
- func (c *Changes) RemoveIndex(indexes ...int)
- type Charset
- type Check
- func NewCheck() *Check
- func (c *Check) AddAttrs(attrs ...Attr) *Check
- func (c *Check) Pos() (*Pos, bool)
- func (c *Check) SetExpr(expr string) *Check
- func (c *Check) SetName(name string) *Check
- func (c *Check) SetPos(p *Pos) *Check
- type Clause
- type Collation
- type Column
- func NewBinaryColumn(name, typ string, opts ...BinaryOption) *Column
- func NewBoolColumn(name, typ string) *Column
- func NewColumn(name string) *Column
- func NewDecimalColumn(name, typ string, opts ...DecimalOption) *Column
- func NewEnumColumn(name string, opts ...EnumOption) *Column
- func NewFloatColumn(name, typ string, opts ...FloatOption) *Column
- func NewIntColumn(name, typ string) *Column
- func NewJSONColumn(name, typ string) *Column
- func NewNullBinaryColumn(name, typ string, opts ...BinaryOption) *Column
- func NewNullBoolColumn(name, typ string) *Column
- func NewNullColumn(name string) *Column
- func NewNullDecimalColumn(name, typ string, opts ...DecimalOption) *Column
- func NewNullEnumColumn(name string, opts ...EnumOption) *Column
- func NewNullFloatColumn(name, typ string, opts ...FloatOption) *Column
- func NewNullIntColumn(name, typ string) *Column
- func NewNullJSONColumn(name, typ string) *Column
- func NewNullSpatialColumn(name, typ string) *Column
- func NewNullStringColumn(name, typ string, opts ...StringOption) *Column
- func NewNullTimeColumn(name, typ string) *Column
- func NewNullUintColumn(name, typ string) *Column
- func NewSpatialColumn(name, typ string) *Column
- func NewStringColumn(name, typ string, opts ...StringOption) *Column
- func NewTimeColumn(name, typ string, opts ...TimeOption) *Column
- func NewUintColumn(name, typ string) *Column
- func (c *Column) AddAttrs(attrs ...Attr) *Column
- func (c *Column) AddIndexes(indexes ...*Index) *Column
- func (c *Column) Pos() (*Pos, bool)
- func (c *Column) SetCharset(v string) *Column
- func (c *Column) SetCollation(v string) *Column
- func (c *Column) SetComment(v string) *Column
- func (c *Column) SetDefault(x Expr) *Column
- func (c *Column) SetGeneratedExpr(x *GeneratedExpr) *Column
- func (c *Column) SetNull(b bool) *Column
- func (c *Column) SetPos(p *Pos) *Column
- func (c *Column) SetType(t Type) *Column
- func (c *Column) UnsetCharset() *Column
- func (c *Column) UnsetCollation() *Column
- type ColumnType
- type Comment
- type DecimalOption
- func DecimalPrecision(precision int) DecimalOption
- func DecimalScale(scale int) DecimalOption
- func DecimalUnsigned(unsigned bool) DecimalOption
- type DecimalType
- type DepRemover
- type DiffMode
- type DiffOption
- type DiffOptions
- func NewDiffOptions(opts ...DiffOption) *DiffOptions
- func (o *DiffOptions) AddOrSkip(changes Changes, cs ...Change) Changes
- func (o *DiffOptions) Skipped(c Change) bool
- type Differ
- type DropAttr
- type DropCheck
- type DropColumn
- type DropForeignKey
- type DropFunc
- type DropIndex
- type DropObject
- type DropPrimaryKey
- type DropProc
- type DropSchema
- type DropTable
- type DropTrigger
- type DropView
- type EnumOption
- func EnumName(name string) EnumOption
- func EnumSchema(s *Schema) EnumOption
- func EnumValues(values ...string) EnumOption
- type EnumType
- type ExecQuerier
- type Expr
- type FloatOption
- type FloatType
- type ForeignKey
- func NewForeignKey(symbol string) *ForeignKey
- func (f *ForeignKey) AddAttrs(attrs ...Attr) *ForeignKey
- func (f *ForeignKey) AddColumns(columns ...*Column) *ForeignKey
- func (f *ForeignKey) AddRefColumns(columns ...*Column) *ForeignKey
- func (f *ForeignKey) Column(name string) (*Column, bool)
- func (f *ForeignKey) Pos() (*Pos, bool)
- func (f *ForeignKey) RefColumn(name string) (*Column, bool)
- func (f *ForeignKey) SetOnDelete(o ReferenceOption) *ForeignKey
- func (f *ForeignKey) SetOnUpdate(o ReferenceOption) *ForeignKey
- func (f *ForeignKey) SetPos(p *Pos) *ForeignKey
- func (f *ForeignKey) SetRefTable(t *Table) *ForeignKey
- func (f *ForeignKey) SetTable(t *Table) *ForeignKey
- type Func
- func (f *Func) AddDeps(objs ...Object) *Func
- func (f *Func) AddRefs(refs ...Object)
- func (f *Func) RemoveDep(o Object)
- type FuncArg
- type FuncArgMode
- type GeneratedExpr
- type IfExists
- type IfNotExists
- type Index
- func NewIndex(name string) *Index
- func NewPrimaryKey(columns ...*Column) *Index
- func NewUniqueIndex(name string) *Index
- func (i *Index) AddAttrs(attrs ...Attr) *Index
- func (i *Index) AddColumns(columns ...*Column) *Index
- func (i *Index) AddExprs(exprs ...Expr) *Index
- func (i *Index) AddParts(parts ...*IndexPart) *Index
- func (i *Index) Pos() (*Pos, bool)
- func (i *Index) SetComment(v string) *Index
- func (i *Index) SetName(name string) *Index
- func (i *Index) SetPos(p *Pos) *Index
- func (i *Index) SetTable(t *Table) *Index
- func (i *Index) SetUnique(b bool) *Index
- type IndexPart
- func NewColumnPart(c *Column) *IndexPart
- func NewExprPart(x Expr) *IndexPart
- func NewIndexPart() *IndexPart
- func (p *IndexPart) AddAttrs(attrs ...Attr) *IndexPart
- func (p *IndexPart) Pos() (*Pos, bool)
- func (p *IndexPart) SetColumn(c *Column) *IndexPart
- func (p *IndexPart) SetDesc(b bool) *IndexPart
- func (p *IndexPart) SetExpr(x Expr) *IndexPart
- func (p *IndexPart) SetPos(p1 *Pos) *IndexPart
- type InspectMode
- type InspectOptions
- type InspectRealmOption
- type Inspector
- type IntegerType
- type JSONType
- type Literal
- type Locker
- type Materialized
- type ModifyAttr
- type ModifyCheck
- type ModifyColumn
- type ModifyForeignKey
- type ModifyFunc
- type ModifyIndex
- type ModifyObject
- type ModifyPrimaryKey
- type ModifyProc
- type ModifySchema
- type ModifyTable
- type ModifyTrigger
- type ModifyView
- type NamedDefault
- type Normalizer
- type NotExistError
- type Object
- type Pos
- func NewFilePos(name string) *Pos
- func (p *Pos) SetEnd(e struct{ Line, Column, Byte int }) *Pos
- func (p *Pos) SetStart(s struct{ Line, Column, Byte int }) *Pos
- type Proc
- func (p *Proc) AddDeps(objs ...Object) *Proc
- func (p *Proc) AddRefs(refs ...Object)
- func (p *Proc) RemoveDep(o Object)
- type RawExpr
- type Realm
- func ExcludeRealm(r *Realm, patterns []string) (*Realm, error)
- func NewRealm(schemas ...*Schema) *Realm
- func (r *Realm) AddObjects(objs ...Object) *Realm
- func (r *Realm) AddSchemas(schemas ...*Schema) *Realm
- func (r *Realm) Object(f func(Object) bool) (Object, bool)
- func (r *Realm) Schema(name string) (*Schema, bool)
- func (r *Realm) SetCharset(v string) *Realm
- func (r *Realm) SetCollation(v string) *Realm
- func (r *Realm) UnsetCharset() *Realm
- func (r *Realm) UnsetCollation() *Realm
- type ReferenceOption
- type RefsAdder
- type RenameColumn
- type RenameFunc
- type RenameIndex
- type RenameObject
- type RenameProc
- type RenameTable
- type RenameTrigger
- type RenameView
- type Schema
- func ExcludeSchema(s *Schema, patterns []string) (*Schema, error)
- func New(name string) *Schema
- func (s *Schema) AddAttrs(attrs ...Attr) *Schema
- func (s *Schema) AddFuncs(funcs ...*Func) *Schema
- func (s *Schema) AddObjects(objs ...Object) *Schema
- func (s *Schema) AddProcs(procs ...*Proc) *Schema
- func (s *Schema) AddTables(tables ...*Table) *Schema
- func (s *Schema) AddViews(views ...*View) *Schema
- func (s *Schema) Func(name string) (*Func, bool)
- func (s *Schema) Materialized(name string) (*View, bool)
- func (s *Schema) Object(f func(Object) bool) (Object, bool)
- func (s *Schema) Pos() (*Pos, bool)
- func (s *Schema) Proc(name string) (*Proc, bool)
- func (s *Schema) SetCharset(v string) *Schema
- func (s *Schema) SetCollation(v string) *Schema
- func (s *Schema) SetComment(v string) *Schema
- func (s *Schema) SetPos(p *Pos) *Schema
- func (s *Schema) SetRealm(r *Realm) *Schema
- func (s *Schema) Table(name string) (*Table, bool)
- func (s *Schema) UnsetCharset() *Schema
- func (s *Schema) UnsetCollation() *Schema
- func (s *Schema) View(name string) (*View, bool)
- type SpatialType
- type SpecTypeNamer
- type StringOption
- type StringType
- type Table
- func NewTable(name string) *Table
- func (t *Table) AddAttrs(attrs ...Attr) *Table
- func (t *Table) AddChecks(checks ...*Check) *Table
- func (t *Table) AddColumns(columns ...*Column) *Table
- func (t *Table) AddDeps(objs ...Object) *Table
- func (t *Table) AddForeignKeys(fks ...*ForeignKey) *Table
- func (t *Table) AddIndexes(indexes ...*Index) *Table
- func (t *Table) AddRefs(refs ...Object)
- func (t *Table) Checks() (ck []*Check)
- func (t *Table) Column(name string) (*Column, bool)
- func (t *Table) ForeignKey(symbol string) (*ForeignKey, bool)
- func (t *Table) Index(name string) (*Index, bool)
- func (t *Table) Pos() (*Pos, bool)
- func (t *Table) RemoveDep(o Object)
- func (t *Table) SetCharset(v string) *Table
- func (t *Table) SetCollation(v string) *Table
- func (t *Table) SetComment(v string) *Table
- func (t *Table) SetPos(p *Pos) *Table
- func (t *Table) SetPrimaryKey(pk *Index) *Table
- func (t *Table) SetSchema(s *Schema) *Table
- func (t *Table) Trigger(name string) (*Trigger, bool)
- func (t *Table) UnsetCharset() *Table
- func (t *Table) UnsetCollation() *Table
- type TimeOption
- type TimeType
- type Trigger
- type TriggerEvent
- type TriggerFor
- type TriggerTime
- type Type
- type TypeFormatter
- type TypeParseFormatter
- type TypeParser
- type UUIDType
- type UnlockFunc
- type UnsupportedType
- type View
- func NewMaterializedView(name, def string) *View
- func NewView(name, def string) *View
- func (v *View) AddAttrs(attrs ...Attr) *View
- func (v *View) AddColumns(columns ...*Column) *View
- func (v *View) AddDeps(objs ...Object) *View
- func (v *View) AddIndexes(indexes ...*Index) *View
- func (v *View) AddRefs(refs ...Object)
- func (v *View) AsTable() *Table
- func (v *View) Column(name string) (*Column, bool)
- func (v *View) Index(name string) (*Index, bool)
- func (v *View) Materialized() bool
- func (v *View) Pos() (*Pos, bool)
- func (v *View) RemoveDep(o Object)
- func (v *View) SetCheckOption(opt string) *View
- func (v *View) SetComment(c string) *View
- func (v *View) SetMaterialized(b bool) *View
- func (v *View) SetPos(p *Pos) *View
- func (v *View) SetSchema(s *Schema) *View
- func (v *View) Trigger(name string) (*Trigger, bool)
- type ViewCheckOption
Examples ¶
Constants ¶
const ( ViewCheckOptionNone = "NONE" ViewCheckOptionLocal = "LOCAL" ViewCheckOptionCascaded = "CASCADED" )
A list of known view check options.
Variables ¶
var ( TriggerEventInsert = TriggerEvent{Name: "INSERT"} TriggerEventUpdate = TriggerEvent{Name: "UPDATE"} TriggerEventDelete = TriggerEvent{Name: "DELETE"} TriggerEventTruncate = TriggerEvent{Name: "TRUNCATE"} )
List of supported trigger events.
ErrLocked is returned on Lock calls which have failed to obtain the lock.
Functions ¶
func IsNotExistError ¶
IsNotExistError reports if an error is a NotExistError.
func IsType ¶
IsType return true if somewhere in the type-chain of t1 is the same as t2.
func ReplaceOrAppend ¶
ReplaceOrAppend searches an attribute of the same type as v in the list and replaces it. Otherwise, v is appended to the list.
func SortRefs ¶
func SortRefs(refs []Object)
SortRefs maintains consistent dependents list.
Types ¶
type AddAttr ¶
type AddAttr struct { A Attr }
AddAttr describes an attribute addition.
type AddCheck ¶
AddCheck describes a CHECK constraint creation change.
type AddColumn ¶
type AddColumn struct { C *Column }
AddColumn describes a column creation change.
type AddForeignKey ¶
type AddForeignKey struct { F *ForeignKey Extra []Clause // Extra clauses and options. }
AddForeignKey describes a foreign-key creation change.
type AddFunc ¶
AddFunc describes a function creation change.
type AddIndex ¶
AddIndex describes an index creation change.
type AddObject ¶
AddObject describes a generic object creation change.
type AddPrimaryKey ¶
type AddPrimaryKey struct { P *Index }
AddPrimaryKey describes a primary-key creation change.
type AddProc ¶
AddProc describes a procedure creation change.
type AddSchema ¶
AddSchema describes a schema (named database) creation change. Unlike table creation, schemas and their elements are described with separate changes. For example, "AddSchema" and "AddTable"
type AddTable ¶
AddTable describes a table creation change.
type AddTrigger ¶
AddTrigger describes a trigger creation change.
type AddView ¶
AddView describes a view creation change.
type Attr ¶
type Attr interface {
// contains filtered or unexported methods
}
Attr represents the interface that all attributes implement.
func RemoveAttr ¶
RemoveAttr returns a new slice where all attributes of type T are filtered.
type BinaryOption ¶
type BinaryOption func(*BinaryType)
BinaryOption allows configuring BinaryType using functional options.
func BinarySize ¶
func BinarySize(size int) BinaryOption
BinarySize configures the size of the binary type.
type BinaryType ¶
BinaryType represents a type that stores a binary data.
type BoolType ¶
type BoolType struct { T string }
BoolType represents a boolean type.
type Change ¶
type Change interface {
// contains filtered or unexported methods
}
A Change represents a schema change. The types below implement this interface and can be used for describing schema changes.
The Change interface can also be implemented outside this package as follows:
type RenameType struct { schema.Change From, To string } var t schema.Change = &RenameType{From: "old", To: "new"}
type ChangeKind ¶
type ChangeKind uint
A ChangeKind describes a change kind that can be combined using a set of flags. The zero kind is no change.
const ( // NoChange holds the zero value of a change kind. NoChange ChangeKind = 0 // ChangeAttr describes attributes change of an element. // For example, a table CHECK was added or changed. ChangeAttr ChangeKind = 1 << (iota - 1) // ChangeCharset describes character-set change. ChangeCharset // ChangeCollate describes collation/encoding change. ChangeCollate // ChangeComment describes comment chang (of any element). ChangeComment // ChangeNull describe a change to the NULL constraint. ChangeNull // ChangeType describe a column type change. ChangeType // ChangeDefault describe a column default change. ChangeDefault // ChangeGenerated describe a change to the generated expression. ChangeGenerated // ChangeUnique describes a change to the uniqueness constraint. // For example, an index was changed from non-unique to unique. ChangeUnique // ChangeParts describes a change to one or more of the index parts. // For example, index keeps its previous name, but the columns order // was changed. ChangeParts // ChangeColumn describes a change to the foreign-key (child) columns. ChangeColumn // ChangeRefColumn describes a change to the foreign-key (parent) columns. ChangeRefColumn // ChangeRefTable describes a change to the foreign-key (parent) table. ChangeRefTable // ChangeUpdateAction describes a change to the foreign-key update action. ChangeUpdateAction // ChangeDeleteAction describes a change to the foreign-key delete action. ChangeDeleteAction )
func (ChangeKind) Is ¶
func (k ChangeKind) Is(c ChangeKind) bool
Is reports whether c is match the given change kind.
func (ChangeKind) String ¶
func (i ChangeKind) String() string
type Changes ¶
type Changes []Change
Changes is a list of changes allow for searching and mutating changes.
func (Changes) IndexAddColumn ¶
IndexAddColumn returns the index of the first AddColumn in the changes with the given name, or -1 if there is no such change in the Changes.
func (Changes) IndexAddIndex ¶
IndexAddIndex returns the index of the first AddIndex in the changes with the given name, or -1 if there is no such change in the Changes.
func (Changes) IndexAddTable ¶
IndexAddTable returns the index of the first AddTable in the changes with the given name, or -1 if there is no such change in the Changes.
func (Changes) IndexDropColumn ¶
IndexDropColumn returns the index of the first DropColumn in the changes with the given name, or -1 if there is no such change in the Changes.
func (Changes) IndexDropIndex ¶
IndexDropIndex returns the index of the first DropIndex in the changes with the given name, or -1 if there is no such change in the Changes.
func (Changes) IndexDropTable ¶
IndexDropTable returns the index of the first DropTable in the changes with the given name, or -1 if there is no such change in the Changes.
func (Changes) IndexModifyColumn ¶
IndexModifyColumn returns the index of the first ModifyColumn in the changes with the given name, or -1 if there is no such change in the Changes.
func (Changes) LastIndexAddTable ¶
LastIndexAddTable returns the index of the last AddTable in the changes with the given name, or -1 if there is no such change in the Changes.
func (Changes) LastIndexDropTable ¶
LastIndexDropTable returns the index of the last DropTable in the changes with the given name, or -1 if there is no such change in the Changes.
func (*Changes) RemoveIndex ¶
RemoveIndex removes elements in the given indexes from the Changes.
Code:play
Output:Example¶
package main
import (
"fmt"
"log"
"ariga.io/atlas/sql/schema"
)
func main() {
changes := schema.Changes{
&schema.AddIndex{I: schema.NewIndex("id")},
&schema.AddColumn{C: schema.NewColumn("new_name")},
&schema.AddColumn{C: schema.NewColumn("id")},
&schema.AddColumn{C: schema.NewColumn("created_at")},
&schema.DropColumn{C: schema.NewColumn("old_name")},
}
i, j := changes.IndexAddColumn("new_name"), changes.IndexDropColumn("old_name")
if i == -1 || j == -1 {
log.Fatalln("Unexpected change positions")
}
// Replace "add" and "drop" with "rename".
changes = append(changes, &schema.RenameColumn{From: changes[j].(*schema.DropColumn).C, To: changes[i].(*schema.AddColumn).C})
changes.RemoveIndex(i, j)
for _, c := range changes {
switch c := c.(type) {
case *schema.AddColumn:
fmt.Printf("%T(%s)\n", c, c.C.Name)
case *schema.DropColumn:
fmt.Printf("%T(%s)\n", c, c.C.Name)
case *schema.RenameColumn:
fmt.Printf("%T(%s -> %s)\n", c, c.From.Name, c.To.Name)
case *schema.AddIndex:
fmt.Printf("%T(%s)\n", c, c.I.Name)
}
}
}
*schema.AddIndex(id)
*schema.AddColumn(id)
*schema.AddColumn(created_at)
*schema.RenameColumn(old_name -> new_name)
type Charset ¶
type Charset struct { V string }
Charset describes a column or a table character-set setting.
type Check ¶
type Check struct { Name string // Optional constraint name. Expr string // Actual CHECK. Attrs []Attr // Additional attributes (e.g. ENFORCED). }
Check describes a CHECK constraint.
func NewCheck ¶
func NewCheck() *Check
NewCheck creates a new check.
func (*Check) AddAttrs ¶
AddAttrs adds additional attributes to the check constraint.
func (*Check) Pos ¶
Pos of the check, if exists.
func (*Check) SetExpr ¶
SetExpr configures the expression of the check constraint.
func (*Check) SetName ¶
SetName configures the name of the check constraint.
func (*Check) SetPos ¶
SetPos sets the position of the check.
type Clause ¶
type Clause interface {
// contains filtered or unexported methods
}
Clause carries additional information that can be added to schema changes. The Clause interface can be implemented outside this package as follows:
type Authorization struct { schema.Clause UserName string } var c schema.Clause = &Authorization{UserName: "a8m"}
type Collation ¶
type Collation struct { V string }
Collation describes a column or a table collation setting.
type Column ¶
type Column struct { Name string Type *ColumnType Default Expr Attrs []Attr Indexes []*Index // Foreign keys that this column is // part of their child columns. ForeignKeys []*ForeignKey }
A Column represents a column definition.
func NewBinaryColumn ¶
func NewBinaryColumn(name, typ string, opts ...BinaryOption) *Column
NewBinaryColumn creates a new BinaryType column.
func NewBoolColumn ¶
NewBoolColumn creates a new BoolType column.
func NewColumn ¶
NewColumn creates a new column with the given name.
func NewDecimalColumn ¶
func NewDecimalColumn(name, typ string, opts ...DecimalOption) *Column
NewDecimalColumn creates a new DecimalType column.
func NewEnumColumn ¶
func NewEnumColumn(name string, opts ...EnumOption) *Column
NewEnumColumn creates a new EnumType column.
func NewFloatColumn ¶
func NewFloatColumn(name, typ string, opts ...FloatOption) *Column
NewFloatColumn creates a new FloatType column.
func NewIntColumn ¶
NewIntColumn creates a new IntegerType column.
func NewJSONColumn ¶
NewJSONColumn creates a new JSONType column.
func NewNullBinaryColumn ¶
func NewNullBinaryColumn(name, typ string, opts ...BinaryOption) *Column
NewNullBinaryColumn creates a new nullable BinaryType column.
func NewNullBoolColumn ¶
NewNullBoolColumn creates a new nullable BoolType column.
func NewNullColumn ¶
NewNullColumn creates a new nullable column with the given name.
func NewNullDecimalColumn ¶
func NewNullDecimalColumn(name, typ string, opts ...DecimalOption) *Column
NewNullDecimalColumn creates a new nullable DecimalType column.
func NewNullEnumColumn ¶
func NewNullEnumColumn(name string, opts ...EnumOption) *Column
NewNullEnumColumn creates a new nullable EnumType column.
func NewNullFloatColumn ¶
func NewNullFloatColumn(name, typ string, opts ...FloatOption) *Column
NewNullFloatColumn creates a new nullable FloatType column.
func NewNullIntColumn ¶
NewNullIntColumn creates a new nullable IntegerType column.
func NewNullJSONColumn ¶
NewNullJSONColumn creates a new nullable JSONType column.
func NewNullSpatialColumn ¶
NewNullSpatialColumn creates a new nullable SpatialType column.
func NewNullStringColumn ¶
func NewNullStringColumn(name, typ string, opts ...StringOption) *Column
NewNullStringColumn creates a new nullable StringType column.
func NewNullTimeColumn ¶
NewNullTimeColumn creates a new nullable TimeType column.
func NewNullUintColumn ¶
NewNullUintColumn creates a new nullable unsigned IntegerType column.
func NewSpatialColumn ¶
NewSpatialColumn creates a new SpatialType column.
func NewStringColumn ¶
func NewStringColumn(name, typ string, opts ...StringOption) *Column
NewStringColumn creates a new StringType column.
func NewTimeColumn ¶
func NewTimeColumn(name, typ string, opts ...TimeOption) *Column
NewTimeColumn creates a new TimeType column.
func NewUintColumn ¶
NewUintColumn creates a new unsigned IntegerType column.
func (*Column) AddAttrs ¶
AddAttrs adds additional attributes to the column.
func (*Column) AddIndexes ¶
AddIndexes appends the references to the indexes this column is part of.
func (*Column) Pos ¶
Pos of the column, if exists.
func (*Column) SetCharset ¶
SetCharset sets or appends the Charset attribute to the column with the given value.
func (*Column) SetCollation ¶
SetCollation sets or appends the Collation attribute to the column with the given value.
func (*Column) SetComment ¶
SetComment sets or appends the Comment attribute to the column with the given value.
func (*Column) SetDefault ¶
SetDefault configures the default of the column
func (*Column) SetGeneratedExpr ¶
func (c *Column) SetGeneratedExpr(x *GeneratedExpr) *Column
SetGeneratedExpr sets or appends the GeneratedExpr attribute.
func (*Column) SetNull ¶
SetNull configures the nullability of the column
func (*Column) SetPos ¶
SetPos sets the position of the column.
func (*Column) SetType ¶
SetType configures the type of the column
func (*Column) UnsetCharset ¶
UnsetCharset unsets the Charset attribute.
func (*Column) UnsetCollation ¶
UnsetCollation the Collation attribute.
type ColumnType ¶
ColumnType represents a column type that is implemented by the dialect.
type Comment ¶
type Comment struct { Text string }
Comment describes a schema element comment.
type DecimalOption ¶
type DecimalOption func(*DecimalType)
DecimalOption allows configuring DecimalType using functional options.
func DecimalPrecision ¶
func DecimalPrecision(precision int) DecimalOption
DecimalPrecision configures the precision of the decimal type.
func DecimalScale ¶
func DecimalScale(scale int) DecimalOption
DecimalScale configures the scale of the decimal type.
func DecimalUnsigned ¶
func DecimalUnsigned(unsigned bool) DecimalOption
DecimalUnsigned configures the unsigned of the float type.
type DecimalType ¶
DecimalType represents a fixed-point type that stores exact numeric values.
type DepRemover ¶
type DepRemover interface { RemoveDep(Object) }
DepRemover wraps the RemoveDep method. Objects that implemented this method allow dependent objects to remove themselves from their references.
type DiffMode ¶
type DiffMode uint8
DiffMode defines the diffing mode, e.g. if objects are normalized or not.
const ( DiffModeUnset DiffMode = iota // Default, backwards compatability. DiffModeNotNormalized // Diff objects are considered to be in not normalized state. DiffModeNormalized // Diff objects are considered to be in normalized state. )
List of diff modes.
func (DiffMode) Is ¶
Is reports whether m is match the given mode.
type DiffOption ¶
type DiffOption func(*DiffOptions)
DiffOption allows configuring the DiffOptions using functional options.
func DiffNormalized ¶
func DiffNormalized() DiffOption
DiffNormalized returns a DiffOption that sets DiffMode to DiffModeNormalized, indicating the Differ should consider input objects as normalized, For example:
DiffNormalized()
func DiffSkipChanges ¶
func DiffSkipChanges(changes ...Change) DiffOption
DiffSkipChanges returns a DiffOption that skips the given change types. For example, in order to skip all destructive changes, use:
DiffSkipChanges(&DropSchema{}, &DropTable{}, &DropColumn{}, &DropIndex{}, &DropForeignKey{})
type DiffOptions ¶
type DiffOptions struct { // SkipChanges defines a list of change types to skip. SkipChanges []Change // DiffMode defines the diffing mode. Mode DiffMode // Extra defines per-driver configuration. If not // nil, should be set to schemahcl.Extension. Extra any // avoid circular dependency with schemahcl. // AskFunc can be implemented by the caller to // make diff process interactive. AskFunc func(string, []string) (string, error) }
DiffOptions defines the standard and per-driver configuration for the schema diffing process.
func NewDiffOptions ¶
func NewDiffOptions(opts ...DiffOption) *DiffOptions
NewDiffOptions creates a new DiffOptions from the given configuration.
func (*DiffOptions) AddOrSkip ¶
func (o *DiffOptions) AddOrSkip(changes Changes, cs ...Change) Changes
AddOrSkip adds the given change to the list of changes if it is not skipped.
func (*DiffOptions) Skipped ¶
func (o *DiffOptions) Skipped(c Change) bool
Skipped reports whether the given change should be skipped.
type Differ ¶
type Differ interface { // RealmDiff returns a diff report for migrating a realm // (or a database) from state "from" to state "to". An error // is returned if such step is not possible. RealmDiff(from, to *Realm, opts ...DiffOption) ([]Change, error) // SchemaDiff returns a diff report for migrating a schema // from state "from" to state "to". An error is returned // if such step is not possible. SchemaDiff(from, to *Schema, opts ...DiffOption) ([]Change, error) // TableDiff returns a diff report for migrating a table // from state "from" to state "to". An error is returned // if such step is not possible. TableDiff(from, to *Table, opts ...DiffOption) ([]Change, error) }
Differ is the interface implemented by the different drivers for comparing and diffing schema top elements.
type DropAttr ¶
type DropAttr struct { A Attr }
DropAttr describes an attribute removal.
type DropCheck ¶
type DropCheck struct { C *Check }
DropCheck describes a CHECK constraint removal change.
type DropColumn ¶
type DropColumn struct { C *Column }
DropColumn describes a column removal change.
type DropForeignKey ¶
type DropForeignKey struct { F *ForeignKey Extra []Clause // Extra clauses and options. }
DropForeignKey describes a foreign-key removal change.
type DropFunc ¶
DropFunc describes a function removal change.
type DropIndex ¶
DropIndex describes an index removal change.
type DropObject ¶
DropObject describes a generic object removal change.
type DropPrimaryKey ¶
type DropPrimaryKey struct { P *Index }
DropPrimaryKey describes a primary-key removal change.
type DropProc ¶
DropProc describes a procedure removal change.
type DropSchema ¶
DropSchema describes a schema (named database) removal change.
type DropTable ¶
DropTable describes a table removal change.
type DropTrigger ¶
DropTrigger describes a trigger removal change.
type DropView ¶
DropView describes a view removal change.
type EnumOption ¶
type EnumOption func(*EnumType)
EnumOption allows configuring EnumType using functional options.
func EnumName ¶
func EnumName(name string) EnumOption
EnumName configures the name of the name. This option is useful for databases like PostgreSQL that supports user-defined types for enums.
func EnumSchema ¶
func EnumSchema(s *Schema) EnumOption
EnumSchema configures the schema of the enum.
func EnumValues ¶
func EnumValues(values ...string) EnumOption
EnumValues configures the values of the enum.
type EnumType ¶
type EnumType struct { T string // Optional type. Values []string // Enum values. Schema *Schema // Optional schema. }
EnumType represents an enum type.
func (*EnumType) SpecName ¶
SpecName returns the name of the spec.
func (*EnumType) SpecType ¶
SpecType returns the type of the spec.
type ExecQuerier ¶
type ExecQuerier interface { QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) }
ExecQuerier wraps the two standard sql.DB methods.
type Expr ¶
type Expr interface {
// contains filtered or unexported methods
}
Expr defines an SQL expression in schema DDL.
The Expr interface can also be implemented outside this package as follows:
type NamedDefault struct { schema.Expr Name string } // Underlying returns the underlying expression. func (e *NamedDefault) Underlying() schema.Expr { return e.Expr } var e schema.Expr = &NamedDefault{Expr: &schema.Literal{V: "bar"}, Name: "foo"}
func UnderlyingExpr ¶
UnderlyingExpr returns the underlying expression of x.
type FloatOption ¶
type FloatOption func(*FloatType)
FloatOption allows configuring FloatType using functional options.
func FloatPrecision ¶
func FloatPrecision(precision int) FloatOption
FloatPrecision configures the precision of the float type.
func FloatUnsigned ¶
func FloatUnsigned(unsigned bool) FloatOption
FloatUnsigned configures the unsigned of the float type.
type FloatType ¶
FloatType represents a floating-point type that stores approximate numeric values.
type ForeignKey ¶
type ForeignKey struct { Symbol string // Constraint name, if exists. Table *Table Columns []*Column RefTable *Table RefColumns []*Column OnUpdate ReferenceOption OnDelete ReferenceOption Attrs []Attr }
A ForeignKey represents an index definition.
func NewForeignKey ¶
func NewForeignKey(symbol string) *ForeignKey
NewForeignKey creates a new foreign-key with the given constraints/symbol name.
func (*ForeignKey) AddAttrs ¶
func (f *ForeignKey) AddAttrs(attrs ...Attr) *ForeignKey
AddAttrs adds additional attributes to the schema.
func (*ForeignKey) AddColumns ¶
func (f *ForeignKey) AddColumns(columns ...*Column) *ForeignKey
AddColumns appends columns to the child-table columns.
func (*ForeignKey) AddRefColumns ¶
func (f *ForeignKey) AddRefColumns(columns ...*Column) *ForeignKey
AddRefColumns appends columns to the parent-table columns.
func (*ForeignKey) Column ¶
func (f *ForeignKey) Column(name string) (*Column, bool)
Column returns the first column that matches the given name.
func (*ForeignKey) Pos ¶
func (f *ForeignKey) Pos() (*Pos, bool)
Pos of the foreign-key, if exists.
func (*ForeignKey) RefColumn ¶
func (f *ForeignKey) RefColumn(name string) (*Column, bool)
RefColumn returns the first referenced column that matches the given name.
func (*ForeignKey) SetOnDelete ¶
func (f *ForeignKey) SetOnDelete(o ReferenceOption) *ForeignKey
SetOnDelete sets the ON DELETE constraint action.
func (*ForeignKey) SetOnUpdate ¶
func (f *ForeignKey) SetOnUpdate(o ReferenceOption) *ForeignKey
SetOnUpdate sets the ON UPDATE constraint action.
func (*ForeignKey) SetPos ¶
func (f *ForeignKey) SetPos(p *Pos) *ForeignKey
SetPos sets the position of the foreign key.
func (*ForeignKey) SetRefTable ¶
func (f *ForeignKey) SetRefTable(t *Table) *ForeignKey
SetRefTable configures the referenced/parent table.
func (*ForeignKey) SetTable ¶
func (f *ForeignKey) SetTable(t *Table) *ForeignKey
SetTable configures the table that holds the foreign-key (child table).
type Func ¶
type Func struct { Name string Schema *Schema Args []*FuncArg Ret Type Body string // Function body only. Lang string // Language (e.g. SQL, PL/pgSQL, etc.). Attrs []Attr // Extra driver specific attributes. Deps []Object // Objects this function depends on. Refs []Object // Objects that depend on this function. }
Func represents a function definition.
func (*Func) AddDeps ¶
AddDeps adds the given objects as dependencies to the function.
func (*Func) AddRefs ¶
AddRefs adds references to the function.
func (*Func) RemoveDep ¶
RemoveDep removes the given object from the function dependencies.
type FuncArg ¶
type FuncArg struct { Name string // Optional name. Type Type // Argument type. Default Expr // Default value. Mode FuncArgMode // Argument mode. Attrs []Attr // Extra driver specific attributes. }
A FuncArg represents a single function argument.
type FuncArgMode ¶
type FuncArgMode string
FuncArgMode represents a function argument mode.
const ( FuncArgModeIn FuncArgMode = "IN" FuncArgModeOut FuncArgMode = "OUT" FuncArgModeInOut FuncArgMode = "INOUT" FuncArgModeVariadic FuncArgMode = "VARIADIC" )
List of supported function argument modes.
type GeneratedExpr ¶
GeneratedExpr describes the expression used for generating the value of a generated/virtual column.
type IfExists ¶
type IfExists struct{}
IfExists represents a clause in a schema change that is commonly supported by multiple statements (e.g. DROP TABLE or DROP SCHEMA).
type IfNotExists ¶
type IfNotExists struct{}
IfNotExists represents a clause in a schema change that is commonly supported by multiple statements (e.g. CREATE TABLE or CREATE SCHEMA).
type Index ¶
type Index struct { Name string Unique bool // Table or View that this index belongs to. Table *Table View *View Attrs []Attr Parts []*IndexPart }
An Index represents an index definition.
func NewIndex ¶
NewIndex creates a new index with the given name.
func NewPrimaryKey ¶
NewPrimaryKey creates a new primary-key index for the given columns.
func NewUniqueIndex ¶
NewUniqueIndex creates a new unique index with the given name.
func (*Index) AddAttrs ¶
AddAttrs adds additional attributes to the index.
func (*Index) AddColumns ¶
AddColumns adds the columns to index parts.
func (*Index) AddExprs ¶
AddExprs adds the expressions to index parts.
func (*Index) AddParts ¶
AddParts appends the given parts.
func (*Index) Pos ¶
Pos of the index, if exists.
func (*Index) SetComment ¶
SetComment sets or appends the Comment attribute to the index with the given value.
func (*Index) SetName ¶
SetName configures the name of the index.
func (*Index) SetPos ¶
SetPos sets the position of the index.
func (*Index) SetTable ¶
SetTable configures the table of the index.
func (*Index) SetUnique ¶
SetUnique configures the uniqueness of the index.
type IndexPart ¶
type IndexPart struct { // SeqNo represents the sequence number of the key part // in the index. SeqNo int // Desc indicates if the key part is stored in descending // order. All databases use ascending order as default. Desc bool X Expr C *Column Attrs []Attr }
An IndexPart represents an index part that can be either an expression or a column.
func NewColumnPart ¶
NewColumnPart creates a new index part with the given column.
func NewExprPart ¶
NewExprPart creates a new index part with the given expression.
func NewIndexPart ¶
func NewIndexPart() *IndexPart
NewIndexPart creates a new index part.
func (*IndexPart) AddAttrs ¶
AddAttrs adds and additional attributes to the index-part.
func (*IndexPart) Pos ¶
Pos of the index part, if exists.
func (*IndexPart) SetColumn ¶
SetColumn sets the column of the index-part.
func (*IndexPart) SetDesc ¶
SetDesc configures the "DESC" attribute of the key part.
func (*IndexPart) SetExpr ¶
SetExpr sets the expression of the index-part.
func (*IndexPart) SetPos ¶
SetPos sets the position of the index part.
type InspectMode ¶
type InspectMode uint
An InspectMode controls the amount and depth of information returned on inspection.
const ( // InspectSchemas enables schema inspection. InspectSchemas InspectMode = 1 << iota // InspectTables enables schema tables inspection including // all its child resources (e.g. columns or indexes). InspectTables // InspectViews enables schema views inspection. InspectViews // InspectFuncs enables schema functions / procedures inspection. InspectFuncs // InspectTypes enables schema types inspection. InspectTypes // InspectObjects enables inspection of database specific // objects like sequences and extensions. InspectObjects // InspectTriggers enables schema triggers inspection. InspectTriggers )
func (InspectMode) Is ¶
func (m InspectMode) Is(i InspectMode) bool
Is reports whether the given mode is enabled.
type InspectOptions ¶
type InspectOptions struct { // Mode defines the amount of information returned by InspectSchema. // If zero, InspectSchema inspects whole resources in the schema. Mode InspectMode // Tables to inspect. Empty means all tables in the schema. Tables []string // Exclude defines a list of glob patterns used to filter resources from inspection. // The syntax used by the different drivers is implemented as follows: // // t // exclude table 't'. // * // exclude all tables. // t.c // exclude column, index and foreign-key named 'c' in table 't'. // t.* // the last item defines the filtering; all resources under 't' are excluded. // *.c // the last item defines the filtering; all resourced named 'c' are excluded in all tables. // *.* // the last item defines the filtering; all resourced under all tables are excluded. // Exclude []string }
InspectOptions describes options for Inspector.
type InspectRealmOption ¶
type InspectRealmOption struct { // Mode defines the amount of information returned by InspectRealm. // If zero, InspectRealm inspects all schemas and their child resources. Mode InspectMode // Schemas to inspect. Empty means all schemas in the realm. Schemas []string // Exclude defines a list of glob patterns used to filter resources from inspection. // The syntax used by the different drivers is implemented as follows: // // s // exclude schema 's'. // * // exclude all schemas. // s.t // exclude table 't' under schema 's'. // s.* // the last item defines the filtering; all tables under 's' are excluded. // *.t // the last item defines the filtering; all tables named 't' are excluded in all schemas. // *.* // the last item defines the filtering; all tables under all schemas are excluded. // *.*.c // the last item defines the filtering; all resourced named 'c' are excluded in all tables. // *.*.* // the last item defines the filtering; all resources are excluded in all tables. // Exclude []string }
InspectRealmOption describes options for RealmInspector.
type Inspector ¶
type Inspector interface { // InspectSchema returns the schema description by its name. An empty name means the // "attached schema" (e.g. SCHEMA() in MySQL or CURRENT_SCHEMA() in PostgreSQL). // A NotExistError error is returned if the schema does not exist in the database. InspectSchema(ctx context.Context, name string, opts *InspectOptions) (*Schema, error) // InspectRealm returns the description of the connected database. InspectRealm(ctx context.Context, opts *InspectRealmOption) (*Realm, error) }
Inspector is the interface implemented by the different database drivers for inspecting schema or databases.
type IntegerType ¶
IntegerType represents an int type.
type JSONType ¶
type JSONType struct { T string }
JSONType represents a JSON type.
type Literal ¶
type Literal struct { V string }
Literal represents a basic literal expression like 1, or '1'. String literals are usually quoted with single or double quotes.
type Locker ¶
type Locker interface { // Lock acquires a named "advisory lock", using the given timeout. Negative value means no timeout, // and the zero value means a "try lock" mode. i.e. return immediately if the lock is already taken. // The returned unlock function is used to release the advisory lock acquired by the session. // // An ErrLocked is returned if the operation failed to obtain the lock in all different timeout modes. Lock(ctx context.Context, name string, timeout time.Duration) (UnlockFunc, error) }
Locker is an interface that is optionally implemented by the different drivers for obtaining an "advisory lock" with the given name.
type Materialized ¶
type Materialized struct { Attr }
Materialized is a schema attribute that attached to views to indicates they are MATERIALIZED VIEWs.
type ModifyAttr ¶
type ModifyAttr struct { From, To Attr }
ModifyAttr describes a change that modifies an element attribute.
type ModifyCheck ¶
type ModifyCheck struct { From, To *Check Change ChangeKind }
ModifyCheck describes a change that modifies a check.
type ModifyColumn ¶
type ModifyColumn struct { From, To *Column Change ChangeKind Extra []Clause // Extra clauses and options. }
ModifyColumn describes a change that modifies a column.
type ModifyForeignKey ¶
type ModifyForeignKey struct { From, To *ForeignKey Change ChangeKind }
ModifyForeignKey describes a change that modifies a foreign-key.
type ModifyFunc ¶
type ModifyFunc struct { From, To *Func // Changes that are extra to the function definition. // For example, adding, dropping, or modifying attributes. Changes []Change }
ModifyFunc describes a function modification change.
type ModifyIndex ¶
type ModifyIndex struct { From, To *Index Change ChangeKind }
ModifyIndex describes an index modification.
type ModifyObject ¶
type ModifyObject struct { From, To Object }
ModifyObject describes a generic object modification change. Unlike tables changes, the diffing types are implemented by the underlying driver.
type ModifyPrimaryKey ¶
type ModifyPrimaryKey struct { From, To *Index Change ChangeKind }
ModifyPrimaryKey describes a primary-key modification.
type ModifyProc ¶
type ModifyProc struct { From, To *Proc // Changes that are extra to the procedure definition. // For example, adding, dropping, or modifying attributes. Changes []Change }
ModifyProc describes a procedure modification change.
type ModifySchema ¶
ModifySchema describes a modification change for schema attributes.
type ModifyTable ¶
ModifyTable describes a table modification change.
type ModifyTrigger ¶
type ModifyTrigger struct { From, To *Trigger // Changes that are extra to the trigger definition. // For example, adding, dropping, or modifying attributes. Changes []Change }
ModifyTrigger describes a trigger modification change.
type ModifyView ¶
type ModifyView struct { From, To *View // Changes that are extra to the view definition. // For example, adding or dropping indexes. Changes []Change }
ModifyView describes a view modification change.
type NamedDefault ¶
NamedDefault defines a named default expression.
func (*NamedDefault) Underlying ¶
func (n *NamedDefault) Underlying() Expr
Underlying returns underlying the expression.
type Normalizer ¶
type Normalizer interface { // NormalizeSchema returns the normal representation of a schema. NormalizeSchema(context.Context, *Schema) (*Schema, error) // NormalizeRealm returns the normal representation of a database. NormalizeRealm(context.Context, *Realm) (*Realm, error) }
Normalizer is the interface implemented by the different database drivers for "normalizing" schema objects. i.e. converting schema objects defined in natural form to their representation in the database. Thus, two schema objects are equal if their normal forms are equal.
type NotExistError ¶
type NotExistError struct { Err error }
A NotExistError wraps another error to retain its original text but makes it possible to the migrator to catch it.
func (NotExistError) Error ¶
func (e NotExistError) Error() string
type Object ¶
type Object interface {
// contains filtered or unexported methods
}
An Object represents a generic database object. Note that this interface is implemented by some top-level types to describe their relationship, and by driver specific types.
type Pos ¶
type Pos struct { // Filename is the name (or full path) of the file which loaded the schema element. Filename string // Start and End represent the bounds of this range. Start, End struct { Line, Column, Byte int // hcl.Pos fields. } }
Pos is an attribute that holds the position of a schema element.
func NewFilePos ¶
NewFilePos creates a file position.
func (*Pos) SetEnd ¶
SetEnd of the position.
func (*Pos) SetStart ¶
SetStart of the position.
type Proc ¶
type Proc struct { Name string Schema *Schema Args []*FuncArg Body string // Function body only. Lang string // Language (e.g. SQL, PL/pgSQL, etc.). Attrs []Attr // Extra driver specific attributes. Deps []Object // Objects this function depends on. Refs []Object // Objects that depend on this Proc. }
Proc represents a procedure definition.
func (*Proc) AddDeps ¶
AddDeps adds the given objects as dependencies to the procedure.
func (*Proc) AddRefs ¶
AddRefs adds references to the procedure.
func (*Proc) RemoveDep ¶
RemoveDep removes the given object from the procedure dependencies.
type RawExpr ¶
type RawExpr struct { X string }
RawExpr represents a raw expression like "uuid()" or "current_timestamp()". Unlike literals, raw expression are usually inlined as is on migration.
type Realm ¶
type Realm struct { Schemas []*Schema Attrs []Attr Objects []Object // Realm-level objects (e.g., users or extensions). }
A Realm or a database describes a domain of schema resources that are logically connected and can be accessed and queried in the same connection (e.g. a physical database instance).
func ExcludeRealm ¶
ExcludeRealm filters resources in the realm based on the given patterns.
func NewRealm ¶
NewRealm creates a new Realm.
func (*Realm) AddObjects ¶
AddObjects adds the given objects to the realm.
func (*Realm) AddSchemas ¶
AddSchemas adds and links the given schemas to the realm.
func (*Realm) Object ¶
Object returns the first object that matched the given predicate.
func (*Realm) Schema ¶
Schema returns the first schema that matched the given name.
func (*Realm) SetCharset ¶
SetCharset sets or appends the Charset attribute to the realm with the given value.
func (*Realm) SetCollation ¶
SetCollation sets or appends the Collation attribute to the realm with the given value.
func (*Realm) UnsetCharset ¶
UnsetCharset unsets the Charset attribute.
func (*Realm) UnsetCollation ¶
UnsetCollation the Collation attribute.
type ReferenceOption ¶
type ReferenceOption string
ReferenceOption for constraint actions.
const ( NoAction ReferenceOption = "NO ACTION" Restrict ReferenceOption = "RESTRICT" Cascade ReferenceOption = "CASCADE" SetNull ReferenceOption = "SET NULL" SetDefault ReferenceOption = "SET DEFAULT" )
Reference options (actions) specified by ON UPDATE and ON DELETE subclauses of the FOREIGN KEY clause.
type RefsAdder ¶
type RefsAdder interface { AddRefs(...Object) }
RefsAdder wraps the AddRefs method. Objects that implemented this method will get their dependent objects automatically set by their AddDeps calls.
type RenameColumn ¶
type RenameColumn struct { From, To *Column }
RenameColumn describes a column rename change.
type RenameFunc ¶
type RenameFunc struct { From, To *Func }
RenameFunc describes a function rename change.
type RenameIndex ¶
type RenameIndex struct { From, To *Index }
RenameIndex describes an index rename change.
type RenameObject ¶
type RenameObject struct { From, To Object }
RenameObject describes a generic object rename change.
type RenameProc ¶
type RenameProc struct { From, To *Proc }
RenameProc describes a procedure rename change.
type RenameTable ¶
type RenameTable struct { From, To *Table }
RenameTable describes a table rename change.
type RenameTrigger ¶
type RenameTrigger struct { From, To *Trigger }
RenameTrigger describes a trigger rename change.
type RenameView ¶
type RenameView struct { From, To *View }
RenameView describes a view rename change.
type Schema ¶
type Schema struct { Name string Realm *Realm Tables []*Table Views []*View Funcs []*Func Procs []*Proc Attrs []Attr // Attrs and options. Objects []Object // Schema-level objects (e.g., types or sequences). }
A Schema describes a database schema (i.e. named database).
func ExcludeSchema ¶
ExcludeSchema filters resources in the schema based on the given patterns.
func New ¶
New creates a new Schema.
func (*Schema) AddAttrs ¶
AddAttrs adds additional attributes to the schema.
func (*Schema) AddFuncs ¶
AddFuncs appends the given functions to the schema.
func (*Schema) AddObjects ¶
AddObjects adds the given objects to the schema.
func (*Schema) AddProcs ¶
AddProcs appends the given procedures to the schema.
func (*Schema) AddTables ¶
AddTables adds and links the given tables to the schema.
func (*Schema) AddViews ¶
AddViews adds and links the given views to the schema.
func (*Schema) Func ¶
Func returns the first function that matched the given name.
func (*Schema) Materialized ¶
Materialized returns the first materialized view that matched the given name.
func (*Schema) Object ¶
Object returns the first object that matched the given predicate.
func (*Schema) Pos ¶
Pos of the schema, if exists.
func (*Schema) Proc ¶
Proc returns the first procedure that matched the given name.
func (*Schema) SetCharset ¶
SetCharset sets or appends the Charset attribute to the schema with the given value.
func (*Schema) SetCollation ¶
SetCollation sets or appends the Collation attribute to the schema with the given value.
func (*Schema) SetComment ¶
SetComment sets or appends the Comment attribute to the schema with the given value.
func (*Schema) SetPos ¶
SetPos sets the position of the schema.
func (*Schema) SetRealm ¶
SetRealm sets the database/realm of the schema.
func (*Schema) Table ¶
Table returns the first table that matched the given name.
func (*Schema) UnsetCharset ¶
UnsetCharset unsets the Charset attribute.
func (*Schema) UnsetCollation ¶
UnsetCollation the Collation attribute.
func (*Schema) View ¶
View returns the first view that matched the given name.
type SpatialType ¶
type SpatialType struct { T string }
SpatialType represents a spatial/geometric type.
type SpecTypeNamer ¶
SpecTypeNamer is an interface that allows to get the spec type and name of the object.
type StringOption ¶
type StringOption func(*StringType)
StringOption allows configuring StringType using functional options.
func StringSize ¶
func StringSize(size int) StringOption
StringSize configures the size of the string type.
type StringType ¶
StringType represents a string type.
type Table ¶
type Table struct { Name string Schema *Schema Columns []*Column Indexes []*Index PrimaryKey *Index ForeignKeys []*ForeignKey Attrs []Attr // Attrs, constraints and options. Triggers []*Trigger // Triggers on the table. Deps []Object // Objects this table depends on. Refs []Object // Objects that depends on this table. }
A Table represents a table definition.
func NewTable ¶
NewTable creates a new Table.
func (*Table) AddAttrs ¶
AddAttrs adds and additional attributes to the table.
func (*Table) AddChecks ¶
AddChecks appends the given checks to the attribute list.
func (*Table) AddColumns ¶
AddColumns appends the given columns to the table column list.
func (*Table) AddDeps ¶
AddDeps adds the given objects as dependencies to the view.
func (*Table) AddForeignKeys ¶
func (t *Table) AddForeignKeys(fks ...*ForeignKey) *Table
AddForeignKeys appends the given foreign-keys to the table foreign-key list.
func (*Table) AddIndexes ¶
AddIndexes appends the given indexes to the table index list.
func (*Table) AddRefs ¶
AddRefs adds references to the table.
func (*Table) Checks ¶
Checks of the table.
func (*Table) Column ¶
Column returns the first column that matched the given name.
func (*Table) ForeignKey ¶
func (t *Table) ForeignKey(symbol string) (*ForeignKey, bool)
ForeignKey returns the first foreign-key that matched the given symbol (constraint name).
func (*Table) Index ¶
Index returns the first index that matched the given name.
func (*Table) Pos ¶
Pos of the table, if exists.
func (*Table) RemoveDep ¶
RemoveDep removes the given object from the table dependencies.
func (*Table) SetCharset ¶
SetCharset sets or appends the Charset attribute to the table with the given value.
func (*Table) SetCollation ¶
SetCollation sets or appends the Collation attribute to the table with the given value.
func (*Table) SetComment ¶
SetComment sets or appends the Comment attribute to the table with the given value.
func (*Table) SetPos ¶
SetPos sets the position of the table.
func (*Table) SetPrimaryKey ¶
SetPrimaryKey sets the primary-key of the table.
func (*Table) SetSchema ¶
SetSchema sets the schema (named-database) of the table.
func (*Table) Trigger ¶
Trigger returns the first trigger that matches the given name.
func (*Table) UnsetCharset ¶
UnsetCharset unsets the Charset attribute.
func (*Table) UnsetCollation ¶
UnsetCollation the Collation attribute.
type TimeOption ¶
type TimeOption func(*TimeType)
TimeOption allows configuring TimeType using functional options.
func TimePrecision ¶
func TimePrecision(precision int) TimeOption
TimePrecision configures the precision of the time type.
func TimeScale ¶
func TimeScale(scale int) TimeOption
TimeScale configures the scale of the time type.
type TimeType ¶
TimeType represents a date/time type.
type Trigger ¶
type Trigger struct { Name string // Table or View that this trigger belongs to. Table *Table View *View ActionTime TriggerTime // BEFORE, AFTER, or INSTEAD OF. Events []TriggerEvent // INSERT, UPDATE, DELETE, etc. For TriggerFor // FOR EACH ROW or FOR EACH STATEMENT. Body string // Trigger body only. Attrs []Attr // WHEN, REFERENCING, etc. Deps []Object // Objects this trigger depends on. Refs []Object // Objects that depend on this trigger. }
A Trigger represents a trigger definition.
type TriggerEvent ¶
type TriggerEvent struct { Name string // Name of the event (e.g. INSERT, UPDATE, DELETE). Columns []*Column // Columns that might be associated with the event. }
TriggerEvent represents the trigger event.
func TriggerEventUpdateOf ¶
func TriggerEventUpdateOf(columns ...*Column) TriggerEvent
TriggerEventUpdateOf returns an UPDATE OF trigger event.
type TriggerFor ¶
type TriggerFor string
TriggerFor represents the trigger FOR EACH spec.
const ( TriggerForRow TriggerFor = "ROW" TriggerForStmt TriggerFor = "STATEMENT" )
List of supported trigger FOR EACH spec.
type TriggerTime ¶
type TriggerTime string
TriggerTime represents the trigger action time.
const ( TriggerTimeBefore TriggerTime = "BEFORE" TriggerTimeAfter TriggerTime = "AFTER" TriggerTimeInstead TriggerTime = "INSTEAD OF" )
List of supported trigger action times.
type Type ¶
type Type interface {
// contains filtered or unexported methods
}
A Type represents a database type. The types below implements this interface and can be used for describing schemas.
The Type interface can also be implemented outside this package as follows:
type SpatialType struct { schema.Type T string } var t schema.Type = &SpatialType{T: "point"}
func UnderlyingType ¶
UnderlyingType returns the underlying type of t.
type TypeFormatter ¶
type TypeFormatter interface { // FormatType converts a schema type to its column form in the database. FormatType(Type) (string, error) }
TypeFormatter is an interface that is required to be implemented by different drivers to format column types into their corresponding database forms.
type TypeParseFormatter ¶
type TypeParseFormatter interface { TypeParser TypeFormatter }
TypeParseFormatter that groups the TypeParser and TypeFormatter interfaces.
type TypeParser ¶
type TypeParser interface { // ParseType converts the raw database type to its schema.Type representation. ParseType(string) (Type, error) }
TypeParser is an interface that is required be implemented by different drivers for parsing column types from their database forms to the schema representation.
type UUIDType ¶
type UUIDType struct { T string }
A UUIDType defines a UUID type.
type UnlockFunc ¶
type UnlockFunc func() error
UnlockFunc is returned by the Locker to explicitly release the named "advisory lock".
type UnsupportedType ¶
type UnsupportedType struct { T string }
UnsupportedType represents a type that is not supported by the drivers.
type View ¶
type View struct { Name string Def string Schema *Schema Columns []*Column Attrs []Attr // Attrs and options. Indexes []*Index // Indexes on materialized view. Triggers []*Trigger // Triggers on the view. Deps []Object // Objects this view depends on. Refs []Object // Objects that depends on this view. }
A View represents a view definition.
func NewMaterializedView ¶
NewMaterializedView creates a new materialized View.
func NewView ¶
NewView creates a new View.
func (*View) AddAttrs ¶
AddAttrs adds and additional attributes to the view.
func (*View) AddColumns ¶
AddColumns appends the given columns to the table column list.
func (*View) AddDeps ¶
AddDeps adds the given objects as dependencies to the view.
func (*View) AddIndexes ¶
AddIndexes appends the given indexes to the table index list.
func (*View) AddRefs ¶
AddRefs adds references to the view.
func (*View) AsTable ¶
AsTable returns a table that represents the view.
func (*View) Column ¶
Column returns the first column that matched the given name.
func (*View) Index ¶
Index returns the first index that matched the given name.
func (*View) Materialized ¶
Materialized reports if the view is materialized.
func (*View) Pos ¶
Pos of the view, if exists.
func (*View) RemoveDep ¶
RemoveDep removes the given object from the view dependencies.
func (*View) SetCheckOption ¶
SetCheckOption sets the check option of the view.
func (*View) SetComment ¶
SetComment sets or appends the Comment attribute to the view with the given value.
func (*View) SetMaterialized ¶
SetMaterialized reports if the view is materialized.
func (*View) SetPos ¶
SetPos sets the position of the view.
func (*View) SetSchema ¶
SetSchema sets the schema (named-database) of the view.
func (*View) Trigger ¶
Trigger returns the first trigger that matches the given name.
type ViewCheckOption ¶
type ViewCheckOption struct { V string // LOCAL, CASCADED, NONE, or driver specific. }
ViewCheckOption describes the standard 'WITH CHECK OPTION clause' of a view.
Source Files ¶
changekind_string.go dsl.go exclude.go inspect.go migrate.go schema.go
- Version
- v0.32.0 (latest)
- Published
- Mar 10, 2025
- Platform
- linux/amd64
- Imports
- 12 packages
- Last checked
- 4 weeks ago –
Tools for package owners.