Documentation
¶
Overview ¶
Package spec defines normalized statement specifications for rule evaluation. input: DDL facts extracted from parser-specific AST adapters output: parser-neutral DDL specification components for rules pos: domain DDL specification model under the unified Statement spec note: if this file changes, update this header and module README.md.
Package spec defines normalized statement specifications for rule evaluation. input: DML facts extracted from parser-specific AST adapters output: parser-neutral DML specification components for rules pos: domain DML specification model under the unified Statement spec note: if this file changes, update this header and module README.md.
Package spec defines normalized statement specifications for rule evaluation. input: parser-neutral DML impact estimation facts attached during audit orchestration output: shared impact contract reused across domain, report, and public API layers pos: domain DML impact model under the unified Statement spec note: if this file changes, update this header and module README.md.
Package spec defines normalized statement specifications for rule evaluation. input: optional metadata-aware audit facts such as instance variables and target-table snapshots output: parser-neutral metadata structures and lookup helpers for future rules pos: domain metadata model shared by offline and metadata-aware audit paths note: if this file changes, update this header and module README.md.
Package spec defines normalized statement specifications for rule evaluation. input: statement data extracted from parser-specific AST adapters output: parser-neutral statement models for domain rule processing pos: domain specification model for all auditable SQL statements note: if this file changes, update this header and module README.md.
Index ¶
- type Alter
- type AlterColumn
- type AlterColumnChange
- type AlterIndex
- type Column
- type Constraint
- type DDL
- type DDLOperation
- type DML
- type DMLOperation
- type Dialect
- type ImpactConfidence
- type ImpactEstimate
- type ImpactRisk
- type ImpactSource
- type Index
- type IndexKind
- type InstanceFacts
- type Kind
- type Metadata
- type PredicateShape
- type Statement
- type StatementExtractor
- type Table
- type TableSnapshot
- type UnsupportedDetail
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alter ¶
type Alter struct {
Action string `json:"action"`
Name string `json:"name,omitempty"`
Column *AlterColumn `json:"column,omitempty"`
Index *AlterIndex `json:"index,omitempty"`
Options map[string]string `json:"options,omitempty"`
}
Alter describes a normalized alter action. Name is the canonical subject identifier for downstream matching: existing-object actions use the pre-change name, pure additions use the created object's name, and table-option actions leave it empty.
type AlterColumn ¶
type AlterColumn struct {
OldName string `json:"old_name,omitempty"`
Definition *Column `json:"definition,omitempty"`
Change *AlterColumnChange `json:"change,omitempty"`
}
AlterColumn describes a column-focused alter payload. OldName is only populated when the action targets an existing column name. Definition carries the target column shape after the action when available. Change carries parser-neutral statement-local relation facts for upcoming source-aware alter rules.
type AlterColumnChange ¶
type AlterColumnChange struct {
TouchesNullability bool `json:"touches_nullability,omitempty"`
TouchesDefault bool `json:"touches_default,omitempty"`
TouchesAutoIncrement bool `json:"touches_auto_increment,omitempty"`
}
AlterColumnChange describes statement-local column-change intent. These flags are parser-neutral hints about what the ALTER statement touches; they do not claim live-schema source truth on their own.
type AlterIndex ¶
type AlterIndex struct {
OldName string `json:"old_name,omitempty"`
Definition *Index `json:"definition,omitempty"`
}
AlterIndex describes an index-focused alter payload. OldName is only populated when the action targets an existing index name. Definition carries the target index shape after the action when available.
type Column ¶
type Column struct {
Name string `json:"name"`
Type string `json:"type,omitempty"`
Length int `json:"length,omitempty"`
Charset string `json:"charset,omitempty"`
Collation string `json:"collation,omitempty"`
Comment string `json:"comment,omitempty"`
Unsigned bool `json:"unsigned,omitempty"`
NotNull bool `json:"not_null,omitempty"`
AutoIncrement bool `json:"auto_increment,omitempty"`
HasDefault bool `json:"has_default,omitempty"`
DefaultValue string `json:"default_value,omitempty"`
DefaultIsNull bool `json:"default_is_null,omitempty"`
DefaultIsCurrentTimestamp bool `json:"default_is_current_timestamp,omitempty"`
OnUpdateCurrentTimestamp bool `json:"on_update_current_timestamp,omitempty"`
}
Column describes a table column.
type Constraint ¶
type Constraint struct {
Type string `json:"type"`
Name string `json:"name,omitempty"`
Columns []string `json:"columns,omitempty"`
}
Constraint describes a non-index table constraint worth preserving for later rules.
type DDL ¶
type DDL struct {
Operation DDLOperation `json:"operation,omitempty"`
Table *Table `json:"table,omitempty"`
Columns []Column `json:"columns,omitempty"`
PrimaryKey *Index `json:"primary_key,omitempty"`
Indexes []Index `json:"indexes,omitempty"`
Constraints []Constraint `json:"constraints,omitempty"`
// Alter also carries standalone DDL action payloads when no table object exists.
Alter []Alter `json:"alter,omitempty"`
Options map[string]string `json:"options,omitempty"`
HasReferTable bool `json:"has_refer_table,omitempty"`
HasSelect bool `json:"has_select,omitempty"`
HasPartition bool `json:"has_partition,omitempty"`
}
DDL contains the structural metadata extracted from a DDL statement.
type DDLOperation ¶
type DDLOperation string
DDLOperation identifies the normalized DDL operation represented by a statement.
const ( DDLOperationUnknown DDLOperation = "unknown" DDLOperationCreateTable DDLOperation = "create_table" DDLOperationCreateView DDLOperation = "create_view" DDLOperationAlterTable DDLOperation = "alter_table" DDLOperationDropTable DDLOperation = "drop_table" DDLOperationDropIndex DDLOperation = "drop_index" DDLOperationCreateIndex DDLOperation = "create_index" DDLOperationDropView DDLOperation = "drop_view" DDLOperationTruncateTable DDLOperation = "truncate_table" )
Supported DDL operations.
type DML ¶
type DML struct {
Operation DMLOperation `json:"operation"`
Tables []Table `json:"tables,omitempty"`
HasWhere bool `json:"has_where"`
HasLimit bool `json:"has_limit"`
HasOrderBy bool `json:"has_order_by"`
HasSubquery bool `json:"has_subquery"`
HasJoin bool `json:"has_join"`
HasJoinOn bool `json:"has_join_on"`
InsertRows int `json:"insert_rows,omitempty"`
IsReplace bool `json:"is_replace,omitempty"`
IsInsertSelect bool `json:"is_insert_select,omitempty"`
HasOnDuplicate bool `json:"has_on_duplicate,omitempty"`
PredicateShape PredicateShape `json:"predicate_shape,omitempty"`
LookupColumns []string `json:"lookup_columns,omitempty"`
MatchedKeyName string `json:"matched_key_name,omitempty"`
MatchedKeyKind IndexKind `json:"matched_key_kind,omitempty"`
IsSingleTable bool `json:"is_single_table,omitempty"`
Impact *ImpactEstimate `json:"impact,omitempty"`
}
DML contains the structural metadata extracted from a DML statement.
type DMLOperation ¶
type DMLOperation string
DMLOperation identifies the normalized DML statement operation.
const ( DMLOperationUnknown DMLOperation = "unknown" DMLOperationInsert DMLOperation = "insert" DMLOperationUpdate DMLOperation = "update" DMLOperationDelete DMLOperation = "delete" )
type ImpactConfidence ¶ added in v0.14.0
type ImpactConfidence string
ImpactConfidence identifies how reliable the estimate source is.
const ( ImpactConfidenceLow ImpactConfidence = "low" ImpactConfidenceMedium ImpactConfidence = "medium" ImpactConfidenceHigh ImpactConfidence = "high" )
type ImpactEstimate ¶ added in v0.14.0
type ImpactEstimate struct {
EstimatedRows *int64 `json:"estimated_rows,omitempty"`
EstimatedRatio *float64 `json:"estimated_ratio,omitempty"`
RiskLevel ImpactRisk `json:"risk_level,omitempty"`
Confidence ImpactConfidence `json:"confidence,omitempty"`
Source ImpactSource `json:"source,omitempty"`
ReasonCodes []string `json:"reason_codes,omitempty"`
Notes []string `json:"notes,omitempty"`
}
ImpactEstimate stores the conservative DML impact estimate attached to a statement.
type ImpactRisk ¶ added in v0.14.0
type ImpactRisk string
ImpactRisk identifies the conservative risk bucket for a DML statement.
const ( ImpactRiskLow ImpactRisk = "low" ImpactRiskMedium ImpactRisk = "medium" ImpactRiskHigh ImpactRisk = "high" ImpactRiskUnknown ImpactRisk = "unknown" )
type ImpactSource ¶ added in v0.14.0
type ImpactSource string
ImpactSource identifies where a DML impact estimate came from.
const ( ImpactSourceShape ImpactSource = "shape" ImpactSourceMetadata ImpactSource = "metadata" ImpactSourcePlan ImpactSource = "plan" )
type Index ¶
type Index struct {
Name string `json:"name"`
Kind IndexKind `json:"kind,omitempty"`
Columns []string `json:"columns,omitempty"`
Cardinality *int64 `json:"cardinality,omitempty"`
}
Index describes an index declaration.
type IndexKind ¶
type IndexKind string
IndexKind identifies the semantic class of an index declaration.
type InstanceFacts ¶
type InstanceFacts struct {
Version string `json:"version,omitempty"`
DefaultCharset string `json:"default_charset,omitempty"`
InnoDBLargePrefixEnabled bool `json:"innodb_large_prefix_enabled,omitempty"`
InnoDBDefaultRowFormat string `json:"innodb_default_row_format,omitempty"`
InnoDBAdaptiveHashEnabled bool `json:"innodb_adaptive_hash_enabled,omitempty"`
}
InstanceFacts are normalized server-level facts that influence audit behavior.
type Metadata ¶
type Metadata struct {
Schema string `json:"schema,omitempty"`
Instance *InstanceFacts `json:"instance,omitempty"`
TargetTable *TableSnapshot `json:"target_table,omitempty"`
}
Metadata carries optional non-SQL facts for one statement evaluation.
type PredicateShape ¶ added in v0.14.0
type PredicateShape string
PredicateShape identifies the normalized WHERE-clause or join pattern for DML.
const ( PredicateShapeUnknown PredicateShape = "unknown" PredicateShapeMissingWhere PredicateShape = "missing_where" PredicateShapeUniqueEquality PredicateShape = "unique_equality" PredicateShapeIndexedPrefixEquality PredicateShape = "indexed_prefix_equality" PredicateShapeIndexedRange PredicateShape = "indexed_range" PredicateShapeJoin PredicateShape = "join" PredicateShapeNonSargable PredicateShape = "non_sargable" PredicateShapeSubquery PredicateShape = "subquery" )
type Statement ¶
type Statement struct {
Kind Kind `json:"kind"`
Dialect Dialect `json:"dialect"`
RawSQL string `json:"raw_sql"`
NormalizedSQL string `json:"normalized_sql,omitempty"`
Warnings []string `json:"warnings,omitempty"`
Line int `json:"line,omitempty"`
Column int `json:"column,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
DDL *DDL `json:"ddl,omitempty"`
DML *DML `json:"dml,omitempty"`
Unsupported *UnsupportedDetail `json:"unsupported,omitempty"`
}
Statement is the normalized domain input for rule evaluation.
type StatementExtractor ¶ added in v0.15.0
StatementExtractor converts one parser-owned statement into the parser-neutral domain model.
type Table ¶
type Table struct {
Schema string `json:"schema,omitempty"`
Name string `json:"name"`
Comment string `json:"comment,omitempty"`
}
Table describes a table-level object.
type TableSnapshot ¶
type TableSnapshot struct {
Schema string `json:"schema,omitempty"`
Exists bool `json:"exists"`
Table *Table `json:"table,omitempty"`
Columns []Column `json:"columns,omitempty"`
PrimaryKey *Index `json:"primary_key,omitempty"`
Indexes []Index `json:"indexes,omitempty"`
Constraints []Constraint `json:"constraints,omitempty"`
Options map[string]string `json:"options,omitempty"`
}
TableSnapshot is the current metadata-backed shape of a target table.
func (TableSnapshot) FindColumn ¶
func (s TableSnapshot) FindColumn(name string) *Column
FindColumn returns the matching column by name, case-insensitively.
func (TableSnapshot) FindIndex ¶
func (s TableSnapshot) FindIndex(name string) *Index
FindIndex returns the matching secondary/unique/fulltext index by name, case-insensitively.
func (TableSnapshot) HasColumn ¶
func (s TableSnapshot) HasColumn(name string) bool
HasColumn reports whether the snapshot contains a column by name, case-insensitively.
func (TableSnapshot) HasIndex ¶
func (s TableSnapshot) HasIndex(name string) bool
HasIndex reports whether the snapshot contains an index by name, case-insensitively.
func (TableSnapshot) HasPrimaryKey ¶
func (s TableSnapshot) HasPrimaryKey() bool
HasPrimaryKey reports whether the snapshot currently has a primary key.