Documentation
¶
Overview ¶
Package schema parses, inspects, and compares database schema definitions.
Index ¶
- func Pluralize(name string) string
- func QualifyPackage(pkgPath string) string
- func RegisterCustomType(name string, typ Type)
- func RegisterCustomTypeResolver(resolver CustomTypeResolver)
- func SaveSnapshot(path string, snap *Snapshot) error
- func StructFieldIndexMap(t reflect.Type) map[string][]int
- func ToSnakeCase(in string) string
- type Builder
- type Column
- type Constraint
- type ConstraintKind
- type CustomTypeResolver
- type Diff
- type DriftReport
- type EnumType
- type Index
- type Inspector
- type Operation
- type OperationKind
- type PostgresInspector
- type Schema
- type ScopeKind
- type Snapshot
- type Table
- type Type
- type TypeKind
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func QualifyPackage ¶
func RegisterCustomType ¶ added in v0.1.1
func RegisterCustomTypeResolver ¶ added in v0.1.1
func RegisterCustomTypeResolver(resolver CustomTypeResolver)
func SaveSnapshot ¶
func StructFieldIndexMap ¶ added in v0.1.1
func ToSnakeCase ¶
Types ¶
type Builder ¶
type Builder struct {
Root string
}
func NewBuilder ¶
NewBuilder returns a schema builder rooted at a source tree.
type Column ¶
type Column struct {
Name string
GoName string
Type Type
Nullable bool
PrimaryKey bool
Unique bool
Identity bool
AutoIncrement bool
Default string
Generated string
SoftDelete bool
CreatedAt bool
UpdatedAt bool
DeletedAt bool
CreatedBy bool
UpdatedBy bool
DeletedBy bool
Version bool
Scope ScopeKind
Tags map[string]string
}
Column describes a database column and its inferred metadata.
func ColumnsFromType ¶ added in v0.1.1
func (Column) IsAuditField ¶
func (Column) IsScopeField ¶
func (Column) TagsString ¶
type Constraint ¶
type Constraint struct {
Name string
Kind ConstraintKind
Columns []string
ReferencedTable string
ReferencedColumns []string
OnDelete string
OnUpdate string
Expression string
Metadata map[string]string
}
Constraint describes a table constraint.
type ConstraintKind ¶
type ConstraintKind string
ConstraintKind identifies a constraint category.
const ( ConstraintPrimaryKey ConstraintKind = "primary_key" ConstraintUnique ConstraintKind = "unique" ConstraintForeignKey ConstraintKind = "foreign_key" ConstraintCheck ConstraintKind = "check" )
type DriftReport ¶ added in v0.1.1
type DriftReport struct {
Expected *Schema
Snapshot *Snapshot
Actual *Schema
ExpectedDiff *Diff
SnapshotDiff *Diff
}
func DetectDrift ¶ added in v0.1.1
func DetectDrift(expected, actual *Schema) (*DriftReport, error)
DetectDrift compares two schemas and returns a drift report.
func DetectDriftFromSource ¶ added in v0.1.1
func DetectDriftFromSource(ctx context.Context, root string, inspector Inspector, db *sql.DB, schemaName, snapshotPath string) (*DriftReport, error)
DetectDriftFromSource builds the expected schema from source and compares it with the live database.
func DetectDriftWithSnapshot ¶ added in v0.1.1
func DetectDriftWithSnapshot(expected *Schema, snapshot *Snapshot, actual *Schema) (*DriftReport, error)
DetectDriftWithSnapshot compares a live schema against an expected schema and snapshot.
func (*DriftReport) Clean ¶ added in v0.1.1
func (r *DriftReport) Clean() bool
Clean reports whether no drift was detected.
func (*DriftReport) HasDrift ¶ added in v0.1.1
func (r *DriftReport) HasDrift() bool
HasDrift reports whether the live schema differs from the expected schema.
func (*DriftReport) HasSnapshotDrift ¶ added in v0.1.1
func (r *DriftReport) HasSnapshotDrift() bool
HasSnapshotDrift reports whether the live schema differs from the snapshot.
type Index ¶
type Index struct {
Name string
Columns []string
Unique bool
Expression string
Where string
Method string
Metadata map[string]string
}
Index describes a database index definition.
type Operation ¶
type Operation struct {
Kind OperationKind
Table string
TableDef *Table
Column *Column
Previous *Column
Index *Index
Constraint *Constraint
}
type OperationKind ¶
type OperationKind string
const ( OpCreateTable OperationKind = "create_table" OpDropTable OperationKind = "drop_table" OpAddColumn OperationKind = "add_column" OpDropColumn OperationKind = "drop_column" OpAlterColumn OperationKind = "alter_column" OpCreateIndex OperationKind = "create_index" OpDropIndex OperationKind = "drop_index" OpCreateConstraint OperationKind = "create_constraint" OpDropConstraint OperationKind = "drop_constraint" )
type PostgresInspector ¶
type PostgresInspector struct{}
PostgresInspector inspects PostgreSQL metadata into a Schema.
type ScopeKind ¶
type ScopeKind string
ScopeKind identifies an access-control scope attached to a column.
type Snapshot ¶
func LoadSnapshot ¶
type Table ¶
type Table struct {
Name string
GoTypeName string
PackageName string
Columns []*Column
Indexes []*Index
Constraints []*Constraint
Comments []string
Metadata map[string]string
}
Table describes a database table or view backing structure.
type Type ¶
type Type struct {
Name string
Kind TypeKind
Length int
Precision int
Scale int
Nullable bool
ArrayOf *Type
EnumValues []string
Metadata map[string]string
}
Type describes a database type with optional metadata.
func ResolveCustomTypeName ¶ added in v0.1.1
ResolveCustomTypeName looks up a registered custom schema type by name.
type TypeKind ¶
type TypeKind string
TypeKind identifies the broad kind of a column type.
const ( TypeUnknown TypeKind = "unknown" TypeBool TypeKind = "bool" TypeInt TypeKind = "int" TypeFloat TypeKind = "float" TypeString TypeKind = "string" TypeBytes TypeKind = "bytes" TypeTime TypeKind = "time" TypeUUID TypeKind = "uuid" TypeJSON TypeKind = "json" TypeArray TypeKind = "array" TypeEnum TypeKind = "enum" TypeCustom TypeKind = "custom" )