pg

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PublicSchemaName is the default schema name for PostgreSQL.
	PublicSchemaName = "public"
)

Variables

This section is empty.

Functions

func ChunkSDLText

func ChunkSDLText(sdlText string) (*schema.SDLChunks, error)

ChunkSDLText parses SDL text and extracts chunks for each database object.

func ExtractFunctionSignature

func ExtractFunctionSignature(ctx *parser.CreatefunctionstmtContext, funcName string) string

ExtractFunctionSignature extracts the function signature with parameter types

func GetDatabaseDefinition

func GetDatabaseDefinition(ctx schema.GetDefinitionContext, metadata *storepb.DatabaseSchemaMetadata) (string, error)

func GetDatabaseMetadata

func GetDatabaseMetadata(schemaText string) (*storepb.DatabaseSchemaMetadata, error)

GetDatabaseMetadata parses the SQL schema text and returns the database metadata.

func GetFunctionDefinition

func GetFunctionDefinition(schema string, function *storepb.FunctionMetadata) (string, error)

func GetMaterializedViewDefinition

func GetMaterializedViewDefinition(schema string, view *storepb.MaterializedViewMetadata) (string, error)

func GetMultiFileDatabaseDefinition

func GetMultiFileDatabaseDefinition(ctx schema.GetDefinitionContext, metadata *storepb.DatabaseSchemaMetadata) (*schema.MultiFileSchemaResult, error)

GetMultiFileDatabaseDefinition generates multi-file SDL schema for PostgreSQL.

func GetSDLDiff

func GetSDLDiff(currentSDLText, previousUserSDLText string, currentSchema, previousSchema *model.DatabaseMetadata) (*schema.MetadataDiff, error)

func GetSchemaDefinition

func GetSchemaDefinition(schema *storepb.SchemaMetadata) (string, error)

func GetSchemaSDLDefinition

func GetSchemaSDLDefinition(schema *storepb.SchemaMetadata) (string, error)

func GetSequenceDefinition

func GetSequenceDefinition(schema string, sequence *storepb.SequenceMetadata) (string, error)

func GetTableDefinition

func GetTableDefinition(schema string, table *storepb.TableMetadata, sequences []*storepb.SequenceMetadata) (string, error)

func GetViewDefinition

func GetViewDefinition(schema string, view *storepb.ViewMetadata) (string, error)

func NormalizePostgreSQLType

func NormalizePostgreSQLType(typeName string) string

normalizePostgreSQLType normalizes PostgreSQL type names to match sync.go output

func WalkThrough

func WalkThrough(d *model.DatabaseMetadata, ast []base.AST) *storepb.Advice

WalkThrough walks through the PostgreSQL ANTLR parse tree and builds catalog metadata.

Types

type CheckConstraintDefWithAST

type CheckConstraintDefWithAST struct {
	Name    string
	ASTNode parser.ITableconstraintContext
}

CheckConstraintDefWithAST holds check constraint definition with its AST node for text comparison

type ColumnDefWithAST

type ColumnDefWithAST struct {
	Name    string
	ASTNode parser.IColumnDefContext
}

ColumnDefWithAST holds a column definition AST node with its name for efficient lookup

type ColumnDefWithASTOrdered

type ColumnDefWithASTOrdered struct {
	Map   map[string]*ColumnDefWithAST
	Order []string // Column names in the order they appear in the AST
}

ColumnDefWithASTOrdered holds column definitions in AST order for deterministic processing

type CreateOrReplaceTriggerVisitor

type CreateOrReplaceTriggerVisitor struct {
	*pgparser.BasePostgreSQLParserVisitor
	// contains filtered or unexported fields
}

CreateOrReplaceTriggerVisitor visits the parse tree and modifies CREATE TRIGGER to CREATE OR REPLACE TRIGGER

func (*CreateOrReplaceTriggerVisitor) Visit

Visit implements the visitor pattern

type CreateOrReplaceVisitor

type CreateOrReplaceVisitor struct {
	*pgparser.BasePostgreSQLParserVisitor
	// contains filtered or unexported fields
}

CreateOrReplaceVisitor visits the parse tree and modifies CREATE FUNCTION to CREATE OR REPLACE FUNCTION

func (*CreateOrReplaceVisitor) Visit

func (v *CreateOrReplaceVisitor) Visit(tree antlr.ParseTree) any

Visit implements the visitor pattern

type ExcludeConstraintDefWithAST

type ExcludeConstraintDefWithAST struct {
	Name    string
	ASTNode parser.ITableconstraintContext
}

ExcludeConstraintDefWithAST holds EXCLUDE constraint definition with its AST node for text comparison

type ForeignKeyDefWithAST

type ForeignKeyDefWithAST struct {
	Name    string
	ASTNode parser.ITableconstraintContext
}

ForeignKeyDefWithAST holds foreign key constraint definition with its AST node for text comparison

type FunctionBodyVisitor

type FunctionBodyVisitor struct {
	*pgparser.BasePostgreSQLParserVisitor
}

FunctionBodyVisitor extracts function body from ANTLR parse tree.

func (*FunctionBodyVisitor) Visit

func (v *FunctionBodyVisitor) Visit(tree antlr.ParseTree) any

Visit implements the visitor pattern for extracting function body.

type FunctionChangeType

type FunctionChangeType int

FunctionChangeType represents the type of change detected in a function.

const (
	FunctionChangeNone FunctionChangeType = iota
	FunctionChangeBodyOnly
	FunctionChangeSignature
	FunctionChangeAttributes
	FunctionChangeBoth // Both signature and body changed
)

type FunctionParameter

type FunctionParameter struct {
	Mode     string // IN, OUT, INOUT, VARIADIC
	Name     string
	DataType string
	Default  string
}

FunctionParameter represents a function parameter.

type FunctionSignature

type FunctionSignature struct {
	Name       string
	Parameters []FunctionParameter
	ReturnType string
	Language   string
	Volatility string // VOLATILE, STABLE, IMMUTABLE
	Security   string // DEFINER, INVOKER
	Parallel   string // UNSAFE, RESTRICTED, SAFE
	Cost       string
	Rows       string
	Leakproof  bool
	Strict     bool
}

FunctionSignature represents the parsed signature of a PostgreSQL function.

type FunctionSignatureVisitor

type FunctionSignatureVisitor struct {
	*pgparser.BasePostgreSQLParserVisitor
}

FunctionSignatureVisitor extracts function signature information from ANTLR parse tree.

func (*FunctionSignatureVisitor) Visit

Visit implements the visitor pattern for extracting function signature from ANTLR parse tree.

type IndexDefWithAST

type IndexDefWithAST struct {
	Name    string
	ASTNode parser.ITableconstraintContext
}

IndexDefWithAST holds index/unique constraint definition with its AST node for text comparison

type IndexDefinition

type IndexDefinition struct {
	IndexName   string
	TableName   string
	Unique      bool
	Method      string // btree, gin, gist, etc.
	Expressions []string
	WhereClause string
}

IndexDefinition represents the parsed structure of a CREATE INDEX statement.

type PostgreSQLFunctionComparer

type PostgreSQLFunctionComparer struct {
	schema.DefaultFunctionComparer
}

PostgreSQLFunctionComparer provides PostgreSQL-specific function comparison logic.

func (*PostgreSQLFunctionComparer) CompareDetailed

CompareDetailed compares two functions with PostgreSQL-specific logic using ANTLR parsing.

func (*PostgreSQLFunctionComparer) Equal

func (c *PostgreSQLFunctionComparer) Equal(oldFunc, newFunc *storepb.FunctionMetadata) bool

Equal compares two functions for equality (implements the interface expected by the schema differ).

type PostgreSQLIndexComparer

type PostgreSQLIndexComparer struct{}

PostgreSQLIndexComparer provides PostgreSQL-specific index comparison logic.

func (*PostgreSQLIndexComparer) CompareIndexWhereConditions

func (c *PostgreSQLIndexComparer) CompareIndexWhereConditions(def1, def2 string) bool

CompareIndexWhereConditions compares WHERE conditions from PostgreSQL index definitions using AST parsing.

func (*PostgreSQLIndexComparer) ExtractWhereClauseFromIndexDef

func (*PostgreSQLIndexComparer) ExtractWhereClauseFromIndexDef(definition string) string

ExtractWhereClauseFromIndexDef extracts the WHERE clause from a CREATE INDEX statement using ANTLR AST parsing.

func (*PostgreSQLIndexComparer) ParseIndexDefinition

func (c *PostgreSQLIndexComparer) ParseIndexDefinition(definition string) (*IndexDefinition, error)

ParseIndexDefinition parses a complete CREATE INDEX statement and returns structured information.

type PostgreSQLViewComparer

type PostgreSQLViewComparer struct {
	schema.DefaultViewComparer
}

PostgreSQLViewComparer provides PostgreSQL-specific view comparison logic.

func (*PostgreSQLViewComparer) CompareMaterializedView

func (c *PostgreSQLViewComparer) CompareMaterializedView(oldMV, newMV *storepb.MaterializedViewMetadata) ([]schema.MaterializedViewChange, error)

CompareMaterializedView compares two materialized views with PostgreSQL-specific logic.

func (*PostgreSQLViewComparer) CompareView

func (c *PostgreSQLViewComparer) CompareView(oldView, newView *storepb.ViewMetadata) ([]schema.ViewChange, error)

CompareView compares two views with PostgreSQL-specific logic using AST semantic analysis.

type PrimaryKeyDefWithAST

type PrimaryKeyDefWithAST struct {
	Name    string
	ASTNode parser.ITableconstraintContext
}

PrimaryKeyDefWithAST represents a primary key constraint definition with its AST node

type SemanticTokens

type SemanticTokens struct {
	SelectItems  []string // normalized select items
	TableRefs    []string // normalized table references
	JoinClauses  []string // normalized join clauses
	WhereClause  string   // normalized where condition
	GroupByItems []string // normalized group by items
	OrderByItems []string // normalized order by items
}

SemanticTokens represents the semantic structure of a SQL query.

type UniqueKeyDefWithAST

type UniqueKeyDefWithAST struct {
	Name    string
	ASTNode parser.ITableconstraintContext
}

UniqueKeyDefWithAST represents a unique key constraint definition with its AST node

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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