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: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSDLDropOperations

func CheckSDLDropOperations(diff *schema.MetadataDiff) []*storepb.Advice

CheckSDLDropOperations analyzes MetadataDiff for DROP and ALTER operations and returns warnings for each DROP detected and info messages for ALTER (CREATE OR REPLACE) operations.

func CheckSDLIntegrity

func CheckSDLIntegrity(files map[string]string) (map[string][]*storepb.Advice, error)

CheckSDLIntegrity performs comprehensive integrity checks across SDL files. This function always handles multiple files to properly validate cross-file references (foreign keys, views) and detect duplicate definitions across files.

Parameters:

  • files: map[filePath]sqlContent - All SDL files to check together. For single-file checking, use a map with one entry.

Returns:

  • map[filePath][]*storepb.Advice - Per-file advice list
  • error - Parse or system errors

func CheckSDLStyle

func CheckSDLStyle(statement string) ([]*storepb.Advice, error)

CheckSDLStyle performs SDL style/convention checks on PostgreSQL declarative schema files.

Style Checks: 1. Disallowed column-level constraints (PRIMARY KEY, UNIQUE, CHECK, FOREIGN KEY must be table-level; NOT NULL, DEFAULT, GENERATED are allowed) 2. Table constraints without explicit names 3. Objects without explicit schema names (tables, indexes, views, sequences, functions) 4. Foreign key references without explicit schema names 5. Indexes without explicit names (unnamed indexes are not allowed)

For integrity checks (foreign key validation, duplicate detection, etc.), use CheckSDLIntegrity from sdl_integrity_check.go.

Types

type BaseRule

type BaseRule struct {
	// contains filtered or unexported fields
}

BaseRule provides common functionality for rules. Other rules can embed this struct to get common behavior.

func (*BaseRule) AddAdvice

func (r *BaseRule) AddAdvice(advice *storepb.Advice)

AddAdvice adds a new advice to the list. Automatically adds baseLine offset to the line number.

func (*BaseRule) GetAdviceList

func (r *BaseRule) GetAdviceList() []*storepb.Advice

GetAdviceList returns the accumulated advice.

func (*BaseRule) SetBaseLine

func (r *BaseRule) SetBaseLine(baseLine int)

SetBaseLine sets the base line for the rule.

type BuiltinPriorBackupCheckAdvisor

type BuiltinPriorBackupCheckAdvisor struct {
}

BuiltinPriorBackupCheckAdvisor is the advisor checking for disallow mix DDL and DML.

func (*BuiltinPriorBackupCheckAdvisor) Check

Check checks for disallow mix DDL and DML.

type CollationAllowlistAdvisor

type CollationAllowlistAdvisor struct {
}

CollationAllowlistAdvisor is the advisor checking for collation allowlist.

func (*CollationAllowlistAdvisor) Check

Check checks for collation allowlist.

type ColumnCommentConventionAdvisor

type ColumnCommentConventionAdvisor struct {
}

ColumnCommentConventionAdvisor is the advisor checking for column comment convention.

func (*ColumnCommentConventionAdvisor) Check

type ColumnDefaultDisallowVolatileAdvisor

type ColumnDefaultDisallowVolatileAdvisor struct {
}

ColumnDefaultDisallowVolatileAdvisor is the advisor checking for column default volatile functions.

func (*ColumnDefaultDisallowVolatileAdvisor) Check

Check checks for column default volatile functions.

type ColumnDisallowChangingTypeAdvisor

type ColumnDisallowChangingTypeAdvisor struct {
}

ColumnDisallowChangingTypeAdvisor is the advisor checking for disallow changing column type.

func (*ColumnDisallowChangingTypeAdvisor) Check

Check checks for disallow changing column type.

type ColumnMaximumCharacterLengthAdvisor

type ColumnMaximumCharacterLengthAdvisor struct {
}

ColumnMaximumCharacterLengthAdvisor is the advisor checking for maximum character length.

func (*ColumnMaximumCharacterLengthAdvisor) Check

Check checks for maximum character length.

type ColumnNoNullAdvisor

type ColumnNoNullAdvisor struct {
}

ColumnNoNullAdvisor is the advisor checking for column no NULL value.

func (*ColumnNoNullAdvisor) Check

Check checks for column no NULL value.

type ColumnRequireDefaultAdvisor

type ColumnRequireDefaultAdvisor struct {
}

ColumnRequireDefaultAdvisor is the advisor checking for column default requirement.

func (*ColumnRequireDefaultAdvisor) Check

Check checks for column default requirement.

type ColumnRequirementAdvisor

type ColumnRequirementAdvisor struct {
}

ColumnRequirementAdvisor is the advisor checking for column requirement.

func (*ColumnRequirementAdvisor) Check

Check checks for the column requirement.

type ColumnTypeDisallowListAdvisor

type ColumnTypeDisallowListAdvisor struct {
}

ColumnTypeDisallowListAdvisor is the advisor checking for column type restriction.

func (*ColumnTypeDisallowListAdvisor) Check

Check checks for column type restriction.

type CommentConventionAdvisor

type CommentConventionAdvisor struct {
}

CommentConventionAdvisor is the advisor checking for comment length.

func (*CommentConventionAdvisor) Check

Check checks for comment length.

type CompatibilityAdvisor

type CompatibilityAdvisor struct {
}

CompatibilityAdvisor is the advisor checking for schema backward compatibility.

func (*CompatibilityAdvisor) Check

Check checks schema backward compatibility.

type EncodingAllowlistAdvisor

type EncodingAllowlistAdvisor struct {
}

EncodingAllowlistAdvisor is the advisor checking for encoding allowlist.

func (*EncodingAllowlistAdvisor) Check

Check checks for encoding allowlist.

type FullyQualifiedObjectNameAdvisor

type FullyQualifiedObjectNameAdvisor struct {
}

FullyQualifiedObjectNameAdvisor is the advisor checking for fully qualified object names.

func (*FullyQualifiedObjectNameAdvisor) Check

Check checks for fully qualified object names.

type GenericChecker

type GenericChecker struct {
	*parser.BasePostgreSQLParserListener
	// contains filtered or unexported fields
}

GenericChecker embeds the base PostgreSQL parser listener and dispatches events to registered rules. This design ensures only one copy of the listener type metadata in the binary.

func NewGenericChecker

func NewGenericChecker(rules []Rule) *GenericChecker

NewGenericChecker creates a new instance of GenericChecker with the given rules.

func (*GenericChecker) EnterEveryRule

func (g *GenericChecker) EnterEveryRule(ctx antlr.ParserRuleContext)

EnterEveryRule is called when any rule is entered. It dispatches the event to all registered rules.

func (*GenericChecker) ExitEveryRule

func (g *GenericChecker) ExitEveryRule(ctx antlr.ParserRuleContext)

ExitEveryRule is called when any rule is exited. It dispatches the event to all registered rules.

func (*GenericChecker) GetAdviceList

func (g *GenericChecker) GetAdviceList() []*storepb.Advice

GetAdviceList collects and returns all advice from registered rules.

func (*GenericChecker) SetBaseLine

func (g *GenericChecker) SetBaseLine(baseLine int)

SetBaseLine sets the base line number for error reporting.

type IndexConcurrentlyAdvisor

type IndexConcurrentlyAdvisor struct {
}

IndexConcurrentlyAdvisor is the advisor checking for to create index concurrently.

func (*IndexConcurrentlyAdvisor) Check

Check checks for to create index concurrently.

type IndexKeyNumberLimitAdvisor

type IndexKeyNumberLimitAdvisor struct {
}

IndexKeyNumberLimitAdvisor is the advisor checking for index key number limit.

func (*IndexKeyNumberLimitAdvisor) Check

Check checks for index key number limit.

type IndexNoDuplicateColumnAdvisor

type IndexNoDuplicateColumnAdvisor struct {
}

IndexNoDuplicateColumnAdvisor is the advisor checking for no duplicate columns in index.

func (*IndexNoDuplicateColumnAdvisor) Check

Check checks for no duplicate columns in index.

type IndexPrimaryKeyTypeAllowlistAdvisor

type IndexPrimaryKeyTypeAllowlistAdvisor struct {
}

IndexPrimaryKeyTypeAllowlistAdvisor is the advisor checking for primary key type allowlist.

func (*IndexPrimaryKeyTypeAllowlistAdvisor) Check

Check checks for primary key type allowlist.

type IndexTotalNumberLimitAdvisor

type IndexTotalNumberLimitAdvisor struct {
}

IndexTotalNumberLimitAdvisor is the advisor checking for index total number limit.

func (*IndexTotalNumberLimitAdvisor) Check

Check checks for index total number limit.

type InsertDisallowOrderByRandAdvisor

type InsertDisallowOrderByRandAdvisor struct {
}

InsertDisallowOrderByRandAdvisor is the advisor checking for to disallow order by rand in INSERT statements.

func (*InsertDisallowOrderByRandAdvisor) Check

Check checks for to disallow order by rand in INSERT statements.

type InsertMustSpecifyColumnAdvisor

type InsertMustSpecifyColumnAdvisor struct {
}

InsertMustSpecifyColumnAdvisor is the advisor checking for to enforce column specified.

func (*InsertMustSpecifyColumnAdvisor) Check

Check checks for to enforce column specified.

type InsertRowLimitAdvisor

type InsertRowLimitAdvisor struct {
}

InsertRowLimitAdvisor is the advisor checking for to limit INSERT rows.

func (*InsertRowLimitAdvisor) Check

Check checks for the INSERT row limit.

type NamingColumnConventionAdvisor

type NamingColumnConventionAdvisor struct {
}

NamingColumnConventionAdvisor is the advisor checking for column naming convention.

func (*NamingColumnConventionAdvisor) Check

Check checks for column naming convention.

type NamingFKConventionAdvisor

type NamingFKConventionAdvisor struct {
}

NamingFKConventionAdvisor is the advisor checking for foreign key naming convention.

func (*NamingFKConventionAdvisor) Check

Check checks for foreign key naming convention.

type NamingIndexConventionAdvisor

type NamingIndexConventionAdvisor struct {
}

NamingIndexConventionAdvisor is the advisor checking for index naming convention.

func (*NamingIndexConventionAdvisor) Check

Check checks for index naming convention.

type NamingPKConventionAdvisor

type NamingPKConventionAdvisor struct {
}

NamingPKConventionAdvisor is the advisor checking for primary key naming convention.

func (*NamingPKConventionAdvisor) Check

Check checks for primary key naming convention.

type NamingTableConventionAdvisor

type NamingTableConventionAdvisor struct {
}

NamingTableConventionAdvisor is the advisor checking for table naming convention.

func (*NamingTableConventionAdvisor) Check

Check checks for table naming convention.

type NamingUKConventionAdvisor

type NamingUKConventionAdvisor struct {
}

NamingUKConventionAdvisor is the advisor checking for unique key naming convention.

func (*NamingUKConventionAdvisor) Check

Check checks for unique key naming convention.

type NoSelectAllAdvisor

type NoSelectAllAdvisor struct {
}

NoSelectAllAdvisor is the advisor checking for no "select *".

func (*NoSelectAllAdvisor) Check

Check checks for no "select *".

type NonTransactionalAdvisor

type NonTransactionalAdvisor struct {
}

NonTransactionalAdvisor is the advisor checking for non-transactional statements.

func (*NonTransactionalAdvisor) Check

Check checks for non-transactional statements.

type Rule

type Rule interface {
	// OnEnter is called when entering a parse tree node
	OnEnter(ctx antlr.ParserRuleContext, nodeType string) error

	// OnExit is called when exiting a parse tree node
	OnExit(ctx antlr.ParserRuleContext, nodeType string) error

	// Name returns the rule name for logging/debugging
	Name() string

	// GetAdviceList returns the accumulated advice from this rule
	GetAdviceList() []*storepb.Advice
}

Rule defines the interface for individual SQL validation rules. Each rule implements specific checking logic without embedding the base listener.

type StatementAddCheckNotValidAdvisor

type StatementAddCheckNotValidAdvisor struct {
}

StatementAddCheckNotValidAdvisor is the advisor checking for to add check not valid.

func (*StatementAddCheckNotValidAdvisor) Check

Check checks for to add check not valid.

type StatementAddFKNotValidAdvisor

type StatementAddFKNotValidAdvisor struct {
}

StatementAddFKNotValidAdvisor is the advisor checking for adding foreign key constraints without NOT VALID.

func (*StatementAddFKNotValidAdvisor) Check

Check checks for adding foreign key constraints without NOT VALID.

type StatementAffectedRowLimitAdvisor

type StatementAffectedRowLimitAdvisor struct {
}

StatementAffectedRowLimitAdvisor is the advisor checking for UPDATE/DELETE affected row limit.

func (*StatementAffectedRowLimitAdvisor) Check

Check checks for UPDATE/DELETE affected row limit.

type StatementCheckSetRoleVariable

type StatementCheckSetRoleVariable struct {
}

func (*StatementCheckSetRoleVariable) Check

type StatementCheckSetRoleVariableRule

type StatementCheckSetRoleVariableRule struct {
	BaseRule
	// contains filtered or unexported fields
}

func (*StatementCheckSetRoleVariableRule) Name

Name returns the rule name.

func (*StatementCheckSetRoleVariableRule) OnEnter

OnEnter is called when entering a parse tree node.

func (*StatementCheckSetRoleVariableRule) OnExit

OnExit is called when exiting a parse tree node.

type StatementCreateSpecifySchema

type StatementCreateSpecifySchema struct {
}

func (*StatementCreateSpecifySchema) Check

type StatementDMLDryRunAdvisor

type StatementDMLDryRunAdvisor struct {
}

StatementDMLDryRunAdvisor is the advisor checking for DML dry run.

func (*StatementDMLDryRunAdvisor) Check

Check checks for DML dry run.

type StatementDisallowAddColumnWithDefaultAdvisor

type StatementDisallowAddColumnWithDefaultAdvisor struct {
}

StatementDisallowAddColumnWithDefaultAdvisor is the advisor checking for to disallow add column with default.

func (*StatementDisallowAddColumnWithDefaultAdvisor) Check

Check checks for to disallow add column with default.

type StatementDisallowAddNotNullAdvisor

type StatementDisallowAddNotNullAdvisor struct {
}

StatementDisallowAddNotNullAdvisor is the advisor checking for to disallow add not null.

func (*StatementDisallowAddNotNullAdvisor) Check

Check checks for to disallow add not null.

type StatementDisallowCommitAdvisor

type StatementDisallowCommitAdvisor struct {
}

StatementDisallowCommitAdvisor is the advisor checking for disallowing COMMIT statements.

func (*StatementDisallowCommitAdvisor) Check

Check checks for disallowing COMMIT statements.

type StatementDisallowOnDelCascadeAdvisor

type StatementDisallowOnDelCascadeAdvisor struct {
}

StatementDisallowOnDelCascadeAdvisor is the advisor checking for ON DELETE CASCADE.

func (*StatementDisallowOnDelCascadeAdvisor) Check

Check checks for ON DELETE CASCADE.

type StatementDisallowRemoveTblCascadeAdvisor

type StatementDisallowRemoveTblCascadeAdvisor struct {
}

StatementDisallowRemoveTblCascadeAdvisor is the advisor checking for disallow CASCADE option when removing tables.

func (*StatementDisallowRemoveTblCascadeAdvisor) Check

Check checks for CASCADE option in DROP TABLE and TRUNCATE TABLE statements.

type StatementMaximumLimitValueAdvisor

type StatementMaximumLimitValueAdvisor struct {
}

StatementMaximumLimitValueAdvisor is the advisor checking for maximum LIMIT value.

func (*StatementMaximumLimitValueAdvisor) Check

Check checks for maximum LIMIT value.

type StatementMergeAlterTableAdvisor

type StatementMergeAlterTableAdvisor struct {
}

StatementMergeAlterTableAdvisor is the advisor checking for no redundant ALTER TABLE statements.

func (*StatementMergeAlterTableAdvisor) Check

Check checks for no redundant ALTER TABLE statements.

type StatementNoLeadingWildcardLikeAdvisor

type StatementNoLeadingWildcardLikeAdvisor struct {
}

StatementNoLeadingWildcardLikeAdvisor is the advisor checking for no leading wildcard LIKE.

func (*StatementNoLeadingWildcardLikeAdvisor) Check

Check checks for no leading wildcard LIKE.

type StatementObjectOwnerCheckAdvisor

type StatementObjectOwnerCheckAdvisor struct {
}

func (*StatementObjectOwnerCheckAdvisor) Check

type StatementType

type StatementType int

StatementType represents the type of DML statement

const (
	StatementTypeUnknown StatementType = iota
	StatementTypeUpdate
	StatementTypeInsert
	StatementTypeDelete
)

type StatementWhereRequiredSelectAdvisor

type StatementWhereRequiredSelectAdvisor struct {
}

StatementWhereRequiredSelectAdvisor is the advisor checking for WHERE clause requirement in SELECT statements.

func (*StatementWhereRequiredSelectAdvisor) Check

Check checks for WHERE clause requirement in SELECT statements.

type StatementWhereRequiredUpdateDeleteAdvisor

type StatementWhereRequiredUpdateDeleteAdvisor struct {
}

StatementWhereRequiredUpdateDeleteAdvisor is the advisor checking for WHERE clause requirement in UPDATE/DELETE.

func (*StatementWhereRequiredUpdateDeleteAdvisor) Check

Check checks for WHERE clause requirement in UPDATE/DELETE statements.

type TableCommentConventionAdvisor

type TableCommentConventionAdvisor struct {
}

TableCommentConventionAdvisor is the advisor checking for table comment convention.

func (*TableCommentConventionAdvisor) Check

type TableDisallowPartitionAdvisor

type TableDisallowPartitionAdvisor struct {
}

TableDisallowPartitionAdvisor is the advisor checking for partitioned tables.

func (*TableDisallowPartitionAdvisor) Check

Check checks for partitioned tables.

type TableDropNamingConventionAdvisor

type TableDropNamingConventionAdvisor struct {
}

TableDropNamingConventionAdvisor is the advisor checking for table drop with naming convention.

func (*TableDropNamingConventionAdvisor) Check

Check checks for table drop with naming convention.

type TableNoFKAdvisor

type TableNoFKAdvisor struct {
}

TableNoFKAdvisor is the advisor checking table disallow foreign key.

func (*TableNoFKAdvisor) Check

func (*TableNoFKAdvisor) Check(_ context.Context, checkCtx advisor.Context) ([]*storepb.Advice, error)

Check checks table disallow foreign key.

type TableReference

type TableReference struct {
	Database      string
	Schema        string
	Table         string
	Alias         string
	StatementType StatementType
}

type TableRequirePKAdvisor

type TableRequirePKAdvisor struct {
}

TableRequirePKAdvisor is the advisor checking table requires PK.

func (*TableRequirePKAdvisor) Check

Check parses the given statement and checks for errors.

Source Files

Jump to

Keyboard shortcuts

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