Documentation
¶
Index ¶
- func CheckSDLDropOperations(diff *schema.MetadataDiff) []*storepb.Advice
- func CheckSDLIntegrity(files map[string]string) (map[string][]*storepb.Advice, error)
- func CheckSDLStyle(statement string) ([]*storepb.Advice, error)
- type BaseRule
- type BuiltinPriorBackupCheckAdvisor
- type CollationAllowlistAdvisor
- type ColumnCommentConventionAdvisor
- type ColumnDefaultDisallowVolatileAdvisor
- type ColumnDisallowChangingTypeAdvisor
- type ColumnMaximumCharacterLengthAdvisor
- type ColumnNoNullAdvisor
- type ColumnRequireDefaultAdvisor
- type ColumnRequirementAdvisor
- type ColumnTypeDisallowListAdvisor
- type CommentConventionAdvisor
- type CompatibilityAdvisor
- type EncodingAllowlistAdvisor
- type FullyQualifiedObjectNameAdvisor
- type GenericChecker
- type IndexConcurrentlyAdvisor
- type IndexKeyNumberLimitAdvisor
- type IndexNoDuplicateColumnAdvisor
- type IndexPrimaryKeyTypeAllowlistAdvisor
- type IndexTotalNumberLimitAdvisor
- type InsertDisallowOrderByRandAdvisor
- type InsertMustSpecifyColumnAdvisor
- type InsertRowLimitAdvisor
- type NamingColumnConventionAdvisor
- type NamingFKConventionAdvisor
- type NamingIndexConventionAdvisor
- type NamingPKConventionAdvisor
- type NamingTableConventionAdvisor
- type NamingUKConventionAdvisor
- type NoSelectAllAdvisor
- type NonTransactionalAdvisor
- type Rule
- type StatementAddCheckNotValidAdvisor
- type StatementAddFKNotValidAdvisor
- type StatementAffectedRowLimitAdvisor
- type StatementCheckSetRoleVariable
- type StatementCheckSetRoleVariableRule
- type StatementCreateSpecifySchema
- type StatementDMLDryRunAdvisor
- type StatementDisallowAddColumnWithDefaultAdvisor
- type StatementDisallowAddNotNullAdvisor
- type StatementDisallowCommitAdvisor
- type StatementDisallowOnDelCascadeAdvisor
- type StatementDisallowRemoveTblCascadeAdvisor
- type StatementMaximumLimitValueAdvisor
- type StatementMergeAlterTableAdvisor
- type StatementNoLeadingWildcardLikeAdvisor
- type StatementObjectOwnerCheckAdvisor
- type StatementType
- type StatementWhereRequiredSelectAdvisor
- type StatementWhereRequiredUpdateDeleteAdvisor
- type TableCommentConventionAdvisor
- type TableDisallowPartitionAdvisor
- type TableDropNamingConventionAdvisor
- type TableNoFKAdvisor
- type TableReference
- type TableRequirePKAdvisor
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 ¶
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 ¶
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 ¶
AddAdvice adds a new advice to the list. Automatically adds baseLine offset to the line number.
func (*BaseRule) GetAdviceList ¶
GetAdviceList returns the accumulated advice.
func (*BaseRule) SetBaseLine ¶
SetBaseLine sets the base line for the rule.
type BuiltinPriorBackupCheckAdvisor ¶
type BuiltinPriorBackupCheckAdvisor struct {
}
BuiltinPriorBackupCheckAdvisor is the advisor checking for disallow mix DDL and DML.
type CollationAllowlistAdvisor ¶
type CollationAllowlistAdvisor struct {
}
CollationAllowlistAdvisor is the advisor checking for collation allowlist.
type ColumnCommentConventionAdvisor ¶
type ColumnCommentConventionAdvisor struct {
}
ColumnCommentConventionAdvisor is the advisor checking for column comment convention.
type ColumnDefaultDisallowVolatileAdvisor ¶
type ColumnDefaultDisallowVolatileAdvisor struct {
}
ColumnDefaultDisallowVolatileAdvisor is the advisor checking for column default volatile functions.
type ColumnDisallowChangingTypeAdvisor ¶
type ColumnDisallowChangingTypeAdvisor struct {
}
ColumnDisallowChangingTypeAdvisor is the advisor checking for disallow changing column type.
type ColumnMaximumCharacterLengthAdvisor ¶
type ColumnMaximumCharacterLengthAdvisor struct {
}
ColumnMaximumCharacterLengthAdvisor is the advisor checking for maximum character length.
type ColumnNoNullAdvisor ¶
type ColumnNoNullAdvisor struct {
}
ColumnNoNullAdvisor is the advisor checking for column no NULL value.
type ColumnRequireDefaultAdvisor ¶
type ColumnRequireDefaultAdvisor struct {
}
ColumnRequireDefaultAdvisor is the advisor checking for column default requirement.
type ColumnRequirementAdvisor ¶
type ColumnRequirementAdvisor struct {
}
ColumnRequirementAdvisor is the advisor checking for column requirement.
type ColumnTypeDisallowListAdvisor ¶
type ColumnTypeDisallowListAdvisor struct {
}
ColumnTypeDisallowListAdvisor is the advisor checking for column type restriction.
type CommentConventionAdvisor ¶
type CommentConventionAdvisor struct {
}
CommentConventionAdvisor is the advisor checking for comment length.
type CompatibilityAdvisor ¶
type CompatibilityAdvisor struct {
}
CompatibilityAdvisor is the advisor checking for schema backward compatibility.
type EncodingAllowlistAdvisor ¶
type EncodingAllowlistAdvisor struct {
}
EncodingAllowlistAdvisor is the advisor checking for encoding allowlist.
type FullyQualifiedObjectNameAdvisor ¶
type FullyQualifiedObjectNameAdvisor struct {
}
FullyQualifiedObjectNameAdvisor is the advisor checking 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.
type IndexKeyNumberLimitAdvisor ¶
type IndexKeyNumberLimitAdvisor struct {
}
IndexKeyNumberLimitAdvisor is the advisor checking for index key number limit.
type IndexNoDuplicateColumnAdvisor ¶
type IndexNoDuplicateColumnAdvisor struct {
}
IndexNoDuplicateColumnAdvisor is the advisor checking for no duplicate columns in index.
type IndexPrimaryKeyTypeAllowlistAdvisor ¶
type IndexPrimaryKeyTypeAllowlistAdvisor struct {
}
IndexPrimaryKeyTypeAllowlistAdvisor is the advisor checking for primary key type allowlist.
type IndexTotalNumberLimitAdvisor ¶
type IndexTotalNumberLimitAdvisor struct {
}
IndexTotalNumberLimitAdvisor is the advisor checking for index total number limit.
type InsertDisallowOrderByRandAdvisor ¶
type InsertDisallowOrderByRandAdvisor struct {
}
InsertDisallowOrderByRandAdvisor is the advisor checking for to disallow order by rand in INSERT statements.
type InsertMustSpecifyColumnAdvisor ¶
type InsertMustSpecifyColumnAdvisor struct {
}
InsertMustSpecifyColumnAdvisor is the advisor checking for to enforce column specified.
type InsertRowLimitAdvisor ¶
type InsertRowLimitAdvisor struct {
}
InsertRowLimitAdvisor is the advisor checking for to limit INSERT rows.
type NamingColumnConventionAdvisor ¶
type NamingColumnConventionAdvisor struct {
}
NamingColumnConventionAdvisor is the advisor checking for column naming convention.
type NamingFKConventionAdvisor ¶
type NamingFKConventionAdvisor struct {
}
NamingFKConventionAdvisor is the advisor checking for foreign key naming convention.
type NamingIndexConventionAdvisor ¶
type NamingIndexConventionAdvisor struct {
}
NamingIndexConventionAdvisor is the advisor checking for index naming convention.
type NamingPKConventionAdvisor ¶
type NamingPKConventionAdvisor struct {
}
NamingPKConventionAdvisor is the advisor checking for primary key naming convention.
type NamingTableConventionAdvisor ¶
type NamingTableConventionAdvisor struct {
}
NamingTableConventionAdvisor is the advisor checking for table naming convention.
type NamingUKConventionAdvisor ¶
type NamingUKConventionAdvisor struct {
}
NamingUKConventionAdvisor is the advisor checking for unique key naming convention.
type NoSelectAllAdvisor ¶
type NoSelectAllAdvisor struct {
}
NoSelectAllAdvisor is the advisor checking for no "select *".
type NonTransactionalAdvisor ¶
type NonTransactionalAdvisor struct {
}
NonTransactionalAdvisor is the advisor checking 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.
type StatementAddFKNotValidAdvisor ¶
type StatementAddFKNotValidAdvisor struct {
}
StatementAddFKNotValidAdvisor is the advisor checking for adding foreign key constraints without NOT VALID.
type StatementAffectedRowLimitAdvisor ¶
type StatementAffectedRowLimitAdvisor struct {
}
StatementAffectedRowLimitAdvisor is the advisor checking for UPDATE/DELETE affected row limit.
type StatementCheckSetRoleVariable ¶
type StatementCheckSetRoleVariable struct {
}
type StatementCheckSetRoleVariableRule ¶
type StatementCheckSetRoleVariableRule struct {
BaseRule
// contains filtered or unexported fields
}
func (*StatementCheckSetRoleVariableRule) Name ¶
func (*StatementCheckSetRoleVariableRule) Name() string
Name returns the rule name.
func (*StatementCheckSetRoleVariableRule) OnEnter ¶
func (r *StatementCheckSetRoleVariableRule) OnEnter(ctx antlr.ParserRuleContext, nodeType string) error
OnEnter is called when entering a parse tree node.
func (*StatementCheckSetRoleVariableRule) OnExit ¶
func (*StatementCheckSetRoleVariableRule) OnExit(_ antlr.ParserRuleContext, _ string) error
OnExit is called when exiting a parse tree node.
type StatementCreateSpecifySchema ¶
type StatementCreateSpecifySchema struct {
}
type StatementDMLDryRunAdvisor ¶
type StatementDMLDryRunAdvisor struct {
}
StatementDMLDryRunAdvisor is the advisor checking for DML dry run.
type StatementDisallowAddColumnWithDefaultAdvisor ¶
type StatementDisallowAddColumnWithDefaultAdvisor struct {
}
StatementDisallowAddColumnWithDefaultAdvisor is the advisor checking for to disallow add column with default.
type StatementDisallowAddNotNullAdvisor ¶
type StatementDisallowAddNotNullAdvisor struct {
}
StatementDisallowAddNotNullAdvisor is the advisor checking for to disallow add not null.
type StatementDisallowCommitAdvisor ¶
type StatementDisallowCommitAdvisor struct {
}
StatementDisallowCommitAdvisor is the advisor checking for disallowing COMMIT statements.
type StatementDisallowOnDelCascadeAdvisor ¶
type StatementDisallowOnDelCascadeAdvisor struct {
}
StatementDisallowOnDelCascadeAdvisor is the advisor checking for ON DELETE CASCADE.
type StatementDisallowRemoveTblCascadeAdvisor ¶
type StatementDisallowRemoveTblCascadeAdvisor struct {
}
StatementDisallowRemoveTblCascadeAdvisor is the advisor checking for disallow CASCADE option when removing tables.
type StatementMaximumLimitValueAdvisor ¶
type StatementMaximumLimitValueAdvisor struct {
}
StatementMaximumLimitValueAdvisor is the advisor checking for maximum LIMIT value.
type StatementMergeAlterTableAdvisor ¶
type StatementMergeAlterTableAdvisor struct {
}
StatementMergeAlterTableAdvisor is the advisor checking for no redundant ALTER TABLE statements.
type StatementNoLeadingWildcardLikeAdvisor ¶
type StatementNoLeadingWildcardLikeAdvisor struct {
}
StatementNoLeadingWildcardLikeAdvisor is the advisor checking for no leading wildcard LIKE.
type StatementObjectOwnerCheckAdvisor ¶
type StatementObjectOwnerCheckAdvisor struct {
}
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.
type StatementWhereRequiredUpdateDeleteAdvisor ¶
type StatementWhereRequiredUpdateDeleteAdvisor struct {
}
StatementWhereRequiredUpdateDeleteAdvisor is the advisor checking for WHERE clause requirement in UPDATE/DELETE.
type TableCommentConventionAdvisor ¶
type TableCommentConventionAdvisor struct {
}
TableCommentConventionAdvisor is the advisor checking for table comment convention.
type TableDisallowPartitionAdvisor ¶
type TableDisallowPartitionAdvisor struct {
}
TableDisallowPartitionAdvisor is the advisor checking for partitioned tables.
type TableDropNamingConventionAdvisor ¶
type TableDropNamingConventionAdvisor struct {
}
TableDropNamingConventionAdvisor is the advisor checking for table drop with naming convention.
type TableNoFKAdvisor ¶
type TableNoFKAdvisor struct {
}
TableNoFKAdvisor is the advisor checking 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.
Source Files
¶
- advisor_builtin_prior_backup_check.go
- advisor_collation_allowlist.go
- advisor_column_comment_convention.go
- advisor_column_default_disallow_volatile.go
- advisor_column_disallow_changing_type.go
- advisor_column_maximum_character_length.go
- advisor_column_no_null.go
- advisor_column_require_default.go
- advisor_column_required.go
- advisor_column_type_disallow_list.go
- advisor_comment_convention.go
- advisor_encoding_allowlist.go
- advisor_index_create_concurrently.go
- advisor_index_key_number_limit.go
- advisor_index_no_duplicate_column.go
- advisor_index_primary_key_type_allowlist.go
- advisor_index_total_number_limit.go
- advisor_insert_disallow_order_by_rand.go
- advisor_insert_must_specify_column.go
- advisor_insert_row_limit.go
- advisor_migration_compatibility.go
- advisor_naming_column.go
- advisor_naming_foreign_key_convention.go
- advisor_naming_fully_qualified.go
- advisor_naming_index_convention.go
- advisor_naming_primary_key_convention.go
- advisor_naming_table.go
- advisor_naming_unique_key_convention.go
- advisor_statement_add_check_not_valid.go
- advisor_statement_add_fk_not_valid.go
- advisor_statement_affected_row_limit.go
- advisor_statement_check_set_role_variable.go
- advisor_statement_create_specify_schema.go
- advisor_statement_disallow_add_column_with_default.go
- advisor_statement_disallow_add_not_null.go
- advisor_statement_disallow_commit.go
- advisor_statement_disallow_on_del_cascade.go
- advisor_statement_disallow_rm_tbl_cascade.go
- advisor_statement_dml_dry_run.go
- advisor_statement_maximum_limit_value.go
- advisor_statement_merge_alter_table.go
- advisor_statement_no_leading_wildcard_like.go
- advisor_statement_no_select_all.go
- advisor_statement_non_transactional.go
- advisor_statement_object_owner_check.go
- advisor_statement_where_required_select.go
- advisor_statement_where_required_update_delete.go
- advisor_table_comment_convention.go
- advisor_table_disallow_partition.go
- advisor_table_drop_naming_convention.go
- advisor_table_no_fk.go
- advisor_table_require_pk.go
- generic_checker.go
- sdl_check.go
- sdl_drop_check.go
- sdl_integrity_check.go
- type_equivalence.go
- utils.go