postgres

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package postgres provides PostgreSQL-specific schema comparison engine.

Overview

This package implements the ComparisonEngine interface for PostgreSQL databases, handling PostgreSQL-specific features and comparison logic.

PostgreSQL-Specific Features

The PostgreSQL engine handles:

  • Schemas (namespaces)
  • Extensions (PostGIS, pg_trgm, etc.)
  • Sequences and IDENTITY columns
  • Enum types
  • Materialized views
  • GIN, GIST, BRIN, and other specialized indexes
  • Partial indexes (WHERE clauses)
  • Expression indexes
  • Rules (rewrite rules)
  • Foreign data wrappers (future)

Type Comparison

PostgreSQL has rich type system with specific comparison rules:

  • VARCHAR vs TEXT vs CHARACTER VARYING
  • SERIAL vs INTEGER with sequence
  • Array types (e.g., INTEGER[])
  • Domain types
  • Custom composite types

The engine normalizes types and handles type aliases to detect true semantic changes.

Schema Awareness

PostgreSQL supports multiple schemas (namespaces) within a database. The engine properly handles qualified names (schema.table) and compares objects within their schema context.

Expression Handling

PostgreSQL expressions require special handling:

  • Type casts (::type vs CAST)
  • Function overloading
  • Operator precedence
  • Array and JSON operators

Compatibility

Supports PostgreSQL 10+ including newer features like declarative partitioning, logical replication objects, and stored procedures (vs functions).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnComparer

type ColumnComparer struct {
	*defaultcomparer.BaseColumnComparer
}

ColumnComparer implements PostgreSQL-specific column comparison.

func NewColumnComparer

func NewColumnComparer() *ColumnComparer

NewColumnComparer creates a new PostgreSQL column comparer.

func (*ColumnComparer) CompareColumns

func (c *ColumnComparer) CompareColumns(oldCol, newCol *schemaextract.Column) (*diff.ColumnDiff, error)

CompareColumns compares two PostgreSQL columns.

func (*ColumnComparer) IsEquivalentType

func (c *ColumnComparer) IsEquivalentType(type1, type2 string) bool

IsEquivalentType checks if two PostgreSQL types are semantically equivalent. Examples:

  • INTEGER = INT = INT4
  • CHARACTER VARYING = VARCHAR
  • TIMESTAMP WITH TIME ZONE = TIMESTAMPTZ

func (*ColumnComparer) NormalizeType

func (c *ColumnComparer) NormalizeType(colType string) string

NormalizeType normalizes a PostgreSQL column type.

type Comparer

type Comparer struct {
	*defaultcomparer.BaseComparer
	// contains filtered or unexported fields
}

Comparer implements PostgreSQL-specific schema comparison.

func NewComparer

func NewComparer() *Comparer

NewComparer creates a new PostgreSQL comparer.

func (*Comparer) Column

func (c *Comparer) Column() engine.ColumnComparer

Column returns the PostgreSQL column comparer.

func (*Comparer) Expression

func (c *Comparer) Expression() engine.ExpressionComparer

Expression returns the PostgreSQL expression comparer.

func (*Comparer) Function

func (c *Comparer) Function() engine.FunctionComparer

Function returns the PostgreSQL function comparer.

func (*Comparer) View

func (c *Comparer) View() engine.ViewComparer

View returns the PostgreSQL view comparer.

type ExpressionComparer

type ExpressionComparer struct {
	engine.ExpressionComparer
}

ExpressionComparer implements PostgreSQL-specific expression comparison.

func NewExpressionComparer

func NewExpressionComparer() *ExpressionComparer

NewExpressionComparer creates a new PostgreSQL expression comparer.

func (*ExpressionComparer) CompareExpressionsSemantically

func (c *ExpressionComparer) CompareExpressionsSemantically(expr1, expr2 string) (bool, error)

CompareExpressionsSemantically compares two PostgreSQL expressions semantically. It normalizes both expressions and uses the parser to compare their ASTs.

func (*ExpressionComparer) IsEquivalentExpression

func (c *ExpressionComparer) IsEquivalentExpression(expr1, expr2 string) bool

IsEquivalentExpression checks if two expressions are semantically equivalent using PostgreSQL-specific rules.

func (*ExpressionComparer) NormalizeExpression

func (c *ExpressionComparer) NormalizeExpression(expr string) string

NormalizeExpression normalizes a PostgreSQL expression. This handles PostgreSQL-specific quirks: - IN (...) to ANY(ARRAY[...]) equivalence - Interval syntax variations - Type cast removal (::type) - Extra parentheses

type FunctionComparer

type FunctionComparer struct {
	*defaultcomparer.BaseFunctionComparer
	// contains filtered or unexported fields
}

FunctionComparer implements PostgreSQL-specific function comparison.

func NewFunctionComparer

func NewFunctionComparer() *FunctionComparer

NewFunctionComparer creates a new PostgreSQL function comparer.

func (*FunctionComparer) CanUseAlterFunction

func (c *FunctionComparer) CanUseAlterFunction(oldFunc, newFunc *schemaextract.Function) bool

CanUseAlterFunction determines if ALTER FUNCTION can be used. PostgreSQL allows ALTER FUNCTION for body changes.

func (*FunctionComparer) CompareDetailed

func (c *FunctionComparer) CompareDetailed(oldFunc, newFunc *schemaextract.Function) (*diff.FunctionComparisonResult, error)

CompareDetailed provides detailed comparison with PostgreSQL-specific logic.

func (*FunctionComparer) Equal

func (c *FunctionComparer) Equal(oldFunc, newFunc *schemaextract.Function) bool

Equal checks if two functions are identical, using semantic comparison for definitions.

func (*FunctionComparer) GetSignature

func (c *FunctionComparer) GetSignature(function *schemaextract.Function) string

GetSignature extracts function signature (name + parameter types).

type ViewComparer

type ViewComparer struct {
	*defaultcomparer.BaseViewComparer
	// contains filtered or unexported fields
}

ViewComparer implements PostgreSQL-specific view comparison.

func NewViewComparer

func NewViewComparer() *ViewComparer

NewViewComparer creates a new PostgreSQL view comparer.

func (*ViewComparer) CompareView

func (c *ViewComparer) CompareView(oldView, newView *schemaextract.View) (*diff.ViewComparisonResult, error)

CompareView compares two views with semantic comparison.

Jump to

Keyboard shortcuts

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