Documentation
¶
Overview ¶
Package diff compares two IR catalogs and produces an ordered migration Plan whose forward (UpSQL) and inverse (DownSQL) DDL can be rendered.
The diff is DB-free: it operates purely on *irv1.Catalog values (typically produced by internal/parse + internal/catalog.Build) and emits PostgreSQL DDL strings. This file defines the Change interface, the Plan container and the concrete change types for the object kinds handled in this task (schemas, types, sequences, tables, columns, constraints, indexes, foreign keys, views, materialized views, functions, procedures and triggers).
Index ¶
- type AddColumn
- type AddConstraint
- type AddEnumValue
- type AlterColumnType
- type Change
- type CreateComposite
- type CreateDomain
- type CreateEnum
- type CreateFunction
- type CreateIndex
- type CreateMatView
- type CreateProcedure
- type CreateRange
- type CreateSchema
- type CreateSequence
- type CreateTable
- type CreateTrigger
- type CreateView
- type DropColumn
- type DropComposite
- type DropConstraint
- type DropDefault
- type DropDomain
- type DropEnum
- type DropFunction
- type DropIndex
- type DropMatView
- type DropNotNull
- type DropProcedure
- type DropRange
- type DropSchema
- type DropSequence
- type DropTable
- type DropTrigger
- type DropView
- type Plan
- type ReplaceFunction
- type ReplaceProcedure
- type ReplaceView
- type SetDefault
- type SetNotNull
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddConstraint ¶
type AddConstraint struct {
Table *irv1.Table
Constraint *irv1.Constraint
}
AddConstraint adds a table constraint (PK/UNIQUE/FK/CHECK/EXCLUSION).
func (*AddConstraint) DownSQL ¶
func (c *AddConstraint) DownSQL() string
func (*AddConstraint) UpSQL ¶
func (c *AddConstraint) UpSQL() string
type AddEnumValue ¶
type AddEnumValue struct {
Enum *irv1.EnumType
Value string
// After is the label this value should be inserted after; empty appends.
After string
}
AddEnumValue adds a single label to an existing enum (irreversible in PG).
func (*AddEnumValue) DownSQL ¶
func (c *AddEnumValue) DownSQL() string
DownSQL is a no-op with a warning: PostgreSQL cannot drop an enum label.
func (*AddEnumValue) UpSQL ¶
func (c *AddEnumValue) UpSQL() string
type AlterColumnType ¶
AlterColumnType changes a column's type using a USING cast.
func (*AlterColumnType) DownSQL ¶
func (c *AlterColumnType) DownSQL() string
func (*AlterColumnType) UpSQL ¶
func (c *AlterColumnType) UpSQL() string
type Change ¶
type Change interface {
// UpSQL renders the forward DDL for this change.
UpSQL() string
// DownSQL renders the inverse DDL for this change.
DownSQL() string
// contains filtered or unexported methods
}
Change is a single reversible schema change.
type CreateComposite ¶
type CreateComposite struct{ Composite *irv1.CompositeType }
CreateComposite creates a composite type.
func (*CreateComposite) DownSQL ¶
func (c *CreateComposite) DownSQL() string
func (*CreateComposite) UpSQL ¶
func (c *CreateComposite) UpSQL() string
type CreateDomain ¶
type CreateDomain struct{ Domain *irv1.DomainType }
CreateDomain creates a domain type.
func (*CreateDomain) DownSQL ¶
func (c *CreateDomain) DownSQL() string
func (*CreateDomain) UpSQL ¶
func (c *CreateDomain) UpSQL() string
type CreateEnum ¶
CreateEnum creates an enum type.
func (*CreateEnum) DownSQL ¶
func (c *CreateEnum) DownSQL() string
func (*CreateEnum) UpSQL ¶
func (c *CreateEnum) UpSQL() string
type CreateFunction ¶
CreateFunction creates a function.
func (*CreateFunction) DownSQL ¶
func (c *CreateFunction) DownSQL() string
func (*CreateFunction) UpSQL ¶
func (c *CreateFunction) UpSQL() string
type CreateIndex ¶
CreateIndex creates an index on a table.
func (*CreateIndex) DownSQL ¶
func (c *CreateIndex) DownSQL() string
func (*CreateIndex) UpSQL ¶
func (c *CreateIndex) UpSQL() string
type CreateMatView ¶
type CreateMatView struct{ View *irv1.MaterializedView }
CreateMatView creates a materialized view.
func (*CreateMatView) DownSQL ¶
func (c *CreateMatView) DownSQL() string
func (*CreateMatView) UpSQL ¶
func (c *CreateMatView) UpSQL() string
type CreateProcedure ¶
CreateProcedure creates a procedure.
func (*CreateProcedure) DownSQL ¶
func (c *CreateProcedure) DownSQL() string
func (*CreateProcedure) UpSQL ¶
func (c *CreateProcedure) UpSQL() string
type CreateRange ¶
CreateRange creates a range type.
func (*CreateRange) DownSQL ¶
func (c *CreateRange) DownSQL() string
func (*CreateRange) UpSQL ¶
func (c *CreateRange) UpSQL() string
type CreateSchema ¶
CreateSchema creates a schema.
func (*CreateSchema) DownSQL ¶
func (c *CreateSchema) DownSQL() string
func (*CreateSchema) UpSQL ¶
func (c *CreateSchema) UpSQL() string
type CreateSequence ¶
CreateSequence creates a sequence.
func (*CreateSequence) DownSQL ¶
func (c *CreateSequence) DownSQL() string
func (*CreateSequence) UpSQL ¶
func (c *CreateSequence) UpSQL() string
type CreateTable ¶
CreateTable creates a table with its columns and inline primary key.
func (*CreateTable) DownSQL ¶
func (c *CreateTable) DownSQL() string
func (*CreateTable) UpSQL ¶
func (c *CreateTable) UpSQL() string
type CreateTrigger ¶
CreateTrigger creates a trigger.
func (*CreateTrigger) DownSQL ¶
func (c *CreateTrigger) DownSQL() string
func (*CreateTrigger) UpSQL ¶
func (c *CreateTrigger) UpSQL() string
type CreateView ¶
CreateView creates a view.
func (*CreateView) DownSQL ¶
func (c *CreateView) DownSQL() string
func (*CreateView) UpSQL ¶
func (c *CreateView) UpSQL() string
type DropColumn ¶
DropColumn drops a column. The inverse re-adds it best-effort with a data-loss warning.
func (*DropColumn) DownSQL ¶
func (c *DropColumn) DownSQL() string
func (*DropColumn) UpSQL ¶
func (c *DropColumn) UpSQL() string
type DropComposite ¶
type DropComposite struct{ Composite *irv1.CompositeType }
DropComposite drops a composite type.
func (*DropComposite) DownSQL ¶
func (c *DropComposite) DownSQL() string
func (*DropComposite) UpSQL ¶
func (c *DropComposite) UpSQL() string
type DropConstraint ¶
type DropConstraint struct {
Table *irv1.Table
Constraint *irv1.Constraint
}
DropConstraint drops a table constraint. The inverse re-adds it.
func (*DropConstraint) DownSQL ¶
func (c *DropConstraint) DownSQL() string
func (*DropConstraint) UpSQL ¶
func (c *DropConstraint) UpSQL() string
type DropDefault ¶
type DropDefault struct {
Table *irv1.Table
Column string
Old *irv1.Expr // previous default, for DownSQL
}
DropDefault removes a column default.
func (*DropDefault) DownSQL ¶
func (c *DropDefault) DownSQL() string
func (*DropDefault) UpSQL ¶
func (c *DropDefault) UpSQL() string
type DropDomain ¶
type DropDomain struct{ Domain *irv1.DomainType }
DropDomain drops a domain type.
func (*DropDomain) DownSQL ¶
func (c *DropDomain) DownSQL() string
func (*DropDomain) UpSQL ¶
func (c *DropDomain) UpSQL() string
type DropFunction ¶
DropFunction drops a function. The inverse re-creates it from its body.
func (*DropFunction) DownSQL ¶
func (c *DropFunction) DownSQL() string
func (*DropFunction) UpSQL ¶
func (c *DropFunction) UpSQL() string
type DropMatView ¶
type DropMatView struct{ View *irv1.MaterializedView }
DropMatView drops a materialized view. The inverse re-creates it (WITH NO DATA on the catalog form; data is not part of the schema).
func (*DropMatView) DownSQL ¶
func (c *DropMatView) DownSQL() string
func (*DropMatView) UpSQL ¶
func (c *DropMatView) UpSQL() string
type DropNotNull ¶
DropNotNull removes a NOT NULL constraint (nullable false -> true).
func (*DropNotNull) DownSQL ¶
func (c *DropNotNull) DownSQL() string
func (*DropNotNull) UpSQL ¶
func (c *DropNotNull) UpSQL() string
type DropProcedure ¶
DropProcedure drops a procedure. The inverse re-creates it from its body.
func (*DropProcedure) DownSQL ¶
func (c *DropProcedure) DownSQL() string
func (*DropProcedure) UpSQL ¶
func (c *DropProcedure) UpSQL() string
type DropSchema ¶
DropSchema drops a schema.
func (*DropSchema) DownSQL ¶
func (c *DropSchema) DownSQL() string
func (*DropSchema) UpSQL ¶
func (c *DropSchema) UpSQL() string
type DropSequence ¶
DropSequence drops a sequence.
func (*DropSequence) DownSQL ¶
func (c *DropSequence) DownSQL() string
func (*DropSequence) UpSQL ¶
func (c *DropSequence) UpSQL() string
type DropTable ¶
DropTable drops a table. The inverse re-creates it best-effort with a data-loss warning.
type DropTrigger ¶
DropTrigger drops a trigger. The inverse re-creates it from its definition.
func (*DropTrigger) DownSQL ¶
func (c *DropTrigger) DownSQL() string
func (*DropTrigger) UpSQL ¶
func (c *DropTrigger) UpSQL() string
type Plan ¶
type Plan struct {
Changes []Change
}
Plan is an ordered set of schema changes.
func Diff ¶
Diff compares two catalogs and produces an ordered Plan of changes that turns `from` into `to`. It handles schemas, types (enum/domain/composite/range), sequences, tables, columns, constraints, indexes, foreign keys, views, materialized views, functions, procedures and triggers.
Iteration is deterministic: object ids are sorted before processing, so the resulting plan is stable for a given input pair.
func (*Plan) DownSQL ¶
DownSQL renders the inverse migration: the exact reverse of the up order, emitting each change's DownSQL. Reversing the up order (rather than re-sorting descending) is required for correctness when a single logical change expands to an ordered pair in the same bucket — e.g. a changed constraint emits [Drop(old), Add(new)] on up, whose correct inverse is [Drop(new).Down=Add(new)... ] reversed to [Add(new).Down=Drop(new), Drop(old).Down=Add(old)], i.e. drop the new then re-add the old.
type ReplaceFunction ¶
ReplaceFunction replaces a function via CREATE OR REPLACE FUNCTION. The inverse restores the previous definition the same way.
func (*ReplaceFunction) DownSQL ¶
func (c *ReplaceFunction) DownSQL() string
func (*ReplaceFunction) UpSQL ¶
func (c *ReplaceFunction) UpSQL() string
type ReplaceProcedure ¶
ReplaceProcedure replaces a procedure via CREATE OR REPLACE PROCEDURE.
func (*ReplaceProcedure) DownSQL ¶
func (c *ReplaceProcedure) DownSQL() string
func (*ReplaceProcedure) UpSQL ¶
func (c *ReplaceProcedure) UpSQL() string
type ReplaceView ¶
ReplaceView replaces a view's definition via CREATE OR REPLACE VIEW. The inverse restores the previous definition the same way.
func (*ReplaceView) DownSQL ¶
func (c *ReplaceView) DownSQL() string
func (*ReplaceView) UpSQL ¶
func (c *ReplaceView) UpSQL() string
type SetDefault ¶
type SetDefault struct {
Table *irv1.Table
Column string
Default *irv1.Expr // new default
Old *irv1.Expr // previous default, for DownSQL (nil => DROP DEFAULT)
}
SetDefault sets (or changes) a column default.
func (*SetDefault) DownSQL ¶
func (c *SetDefault) DownSQL() string
func (*SetDefault) UpSQL ¶
func (c *SetDefault) UpSQL() string
type SetNotNull ¶
SetNotNull adds a NOT NULL constraint to a column (nullable true -> false).
func (*SetNotNull) DownSQL ¶
func (c *SetNotNull) DownSQL() string
func (*SetNotNull) UpSQL ¶
func (c *SetNotNull) UpSQL() string