Documentation
¶
Index ¶
- func FunctionLookup(functions []*ir.Function) map[string]struct{}
- func FunctionReferencesRelation(fn *ir.Function, relations map[string]struct{}) bool
- func FunctionSignatureReferencesRelation(fn *ir.Function, relations map[string]struct{}) bool
- func GenerateDumpHeader(schemaIR *ir.IR) string
- func RelationLookup(tables []*ir.Table, views []*ir.View) map[string]struct{}
- func SQLFunctionCallsFunction(fn *ir.Function, functions map[string]struct{}) bool
- type ColumnDiff
- type ConstraintDiff
- type Diff
- func GenerateDump(schema *ir.IR, targetSchema string, qualifySchema bool) ([]Diff, error)
- func GenerateMigration(oldIR, newIR *ir.IR, targetSchema string) []Diff
- func GenerateMigrationForTarget(oldIR, newIR *ir.IR, targetSchema string, targetMajorVersion int) []Diff
- func GenerateMigrationWithOptions(oldIR, newIR *ir.IR, targetSchema string, qualifySchema bool) []Diff
- type DiffOperation
- type DiffSource
- type DiffType
- type IndexDiff
- type SQLStatement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FunctionLookup ¶ added in v1.13.4
FunctionSignatureReferencesRelation reports whether a function's return type or parameter types name a relation in the lookup (see RelationLookup). Such a function must be created after that relation exists. FunctionLookup builds the lookup SQLFunctionCallsFunction expects.
func FunctionReferencesRelation ¶ added in v1.13.0
FunctionReferencesRelation reports whether a function's signature or body references a relation in the lookup (see RelationLookup). This is the same check the diff uses to order functions after the tables they query (#530).
func FunctionSignatureReferencesRelation ¶ added in v1.13.0
func GenerateDumpHeader ¶
GenerateDumpHeader generates the header for database dumps with metadata
func RelationLookup ¶ added in v1.13.0
RelationLookup builds a case-insensitive lookup of table and view names, keyed both unqualified and schema-qualified, for use with FunctionSignatureReferencesRelation.
func SQLFunctionCallsFunction ¶ added in v1.13.4
SQLFunctionCallsFunction reports whether a SQL-language function's body calls one of the functions in the lookup. PostgreSQL resolves such a body when the function is created, so the callee must exist by then.
Types ¶
type ColumnDiff ¶
ColumnDiff represents changes to a column
func (*ColumnDiff) GetObjectName ¶
func (d *ColumnDiff) GetObjectName() string
type ConstraintDiff ¶
type ConstraintDiff struct {
Old *ir.Constraint
New *ir.Constraint
}
ConstraintDiff represents changes to a constraint
func (*ConstraintDiff) GetObjectName ¶
func (d *ConstraintDiff) GetObjectName() string
type Diff ¶
type Diff struct {
Statements []SQLStatement `json:"statements"`
Type DiffType `json:"type"`
Operation DiffOperation `json:"operation"` // create, alter, drop, replace
Path string `json:"path"`
Source DiffSource `json:"-"` // interface; not JSON-serializable (see #305)
}
Diff represents one or more related SQL statements with their source change
func GenerateDump ¶ added in v1.13.2
GenerateDump creates an empty-to-target export while preserving partitioned index identities. Migrations use the same schedule for complete new hierarchies.
func GenerateMigration ¶
GenerateMigration compares two IR schemas and returns the SQL differences GenerateMigration generates the migration diff using standard "smart qualification" (the target-schema prefix is omitted on entity names).
func GenerateMigrationForTarget ¶ added in v1.13.1
func GenerateMigrationForTarget(oldIR, newIR *ir.IR, targetSchema string, targetMajorVersion int) []Diff
GenerateMigrationForTarget is GenerateMigration for a target database whose PostgreSQL major version is known (0 if unknown, treated as a current server). The version gates DDL that only newer servers accept, such as ALTER COLUMN ... SET EXPRESSION AS (PostgreSQL 17+); older targets get a version-portable equivalent instead (issue #591).
func GenerateMigrationWithOptions ¶ added in v1.12.0
func GenerateMigrationWithOptions(oldIR, newIR *ir.IR, targetSchema string, qualifySchema bool) []Diff
GenerateMigrationWithOptions is like GenerateMigration, but when qualifySchema is true the empty-to-target create DDL used by `dump --qualify-schema` forces schema qualification for structural object identifiers where the IR carries schema identity (table/view/index/sequence/type/function/procedure/policy names and ON/REFERENCES/OWNED BY/COMMENT targets). This option is intended for dump's empty-to-target CREATE/ADD output; other diff paths are not part of the contract and may still use standard smart qualification. Same-schema type references stay bare because the IR stores them without schema identity (#493). Default behavior (false) is unchanged for plan/apply.
type DiffOperation ¶
type DiffOperation int
DiffOperation represents the operation being performed
const ( DiffOperationCreate DiffOperation = iota DiffOperationAlter DiffOperationDrop // DiffOperationRecreate indicates a DROP that is part of a DROP+CREATE cycle // for dependency handling. The object will be recreated, so this should be // counted as a modification in summaries, not a destruction. DiffOperationRecreate // DiffOperationAttach indicates an explicit partition index attachment. DiffOperationAttach )
func (DiffOperation) MarshalJSON ¶
func (d DiffOperation) MarshalJSON() ([]byte, error)
MarshalJSON marshals DiffOperation to JSON as a string
func (DiffOperation) String ¶
func (d DiffOperation) String() string
String returns the string representation of DiffOperation
func (*DiffOperation) UnmarshalJSON ¶
func (d *DiffOperation) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals DiffOperation from JSON string
type DiffSource ¶
type DiffSource interface {
GetObjectName() string // Returns the object name (preserves names with dots like "public.idx_users")
}
DiffSource represents all possible source types for a diff
type DiffType ¶
type DiffType int
DiffType represents the type of database object being changed
const ( DiffTypeTable DiffType = iota DiffTypeTableColumn DiffTypeTableIndex DiffTypeTableTrigger DiffTypeTablePolicy DiffTypeTableRLS DiffTypeTableConstraint DiffTypeTableComment DiffTypeTableColumnComment DiffTypeTableIndexComment DiffTypeTablePersistence DiffTypeView DiffTypeViewTrigger DiffTypeViewComment DiffTypeMaterializedView DiffTypeMaterializedViewComment DiffTypeMaterializedViewIndex DiffTypeMaterializedViewIndexComment DiffTypeFunction DiffTypeProcedure DiffTypeAggregate DiffTypeSequence DiffTypeType DiffTypeDomain DiffTypeComment DiffTypeDefaultPrivilege DiffTypePrivilege DiffTypeRevokedDefaultPrivilege DiffTypeColumnPrivilege )
func (DiffType) MarshalJSON ¶
MarshalJSON marshals DiffType to JSON as a string
func (*DiffType) UnmarshalJSON ¶
UnmarshalJSON unmarshals DiffType from JSON string
type SQLStatement ¶
type SQLStatement struct {
SQL string `json:"sql,omitempty"`
CanRunInTransaction bool `json:"can_run_in_transaction"`
// RequiresCommitAfter forces a transaction boundary right after this
// statement: later statements must not share its transaction. Used for
// ALTER TYPE ... ADD VALUE, whose new label is unusable until committed
// (SQLSTATE 55P04, issue #600).
RequiresCommitAfter bool `json:"-"`
}
SQLStatement represents a single SQL statement with its transaction capability