tracking

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package tracking provides database object lifecycle tracking and dependency management. It maintains state of database objects across migrations, analyzes dependencies, and supports the migration consolidation pipeline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBaseTypeName

func GetBaseTypeName(typeName string) string

GetBaseTypeName extracts the base type from an array type E.g., "double precision[]" -> "double precision"

func IsArrayDataType

func IsArrayDataType(typeName string) bool

IsArrayDataType determines if a type is an array

func IsSpatialDataType

func IsSpatialDataType(typeName string) bool

IsSpatialDataType determines if a PostgreSQL type is a spatial/geometric type

Types

type AdvancedDDLCycleDetector

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

AdvancedDDLCycleDetector detects and analyzes complex DDL cycles

func NewAdvancedDDLCycleDetector

func NewAdvancedDDLCycleDetector(config CycleDetectionConfig) *AdvancedDDLCycleDetector

NewAdvancedDDLCycleDetector creates a new advanced DDL cycle detector

func (*AdvancedDDLCycleDetector) DetectCycles

func (d *AdvancedDDLCycleDetector) DetectCycles(lifecycles map[string]*ObjectLifecycle) ([]DDLCycle, error)

DetectCycles analyzes object lifecycles to identify DDL cycles

type ChangeContext

type ChangeContext struct {
	Database     string            `json:"database"`
	SearchPath   []string          `json:"search_path"`
	Transaction  string            `json:"transaction,omitempty"`
	User         string            `json:"user,omitempty"`
	Application  string            `json:"application,omitempty"`
	Environment  string            `json:"environment,omitempty"`
	Tags         map[string]string `json:"tags,omitempty"`
	Reason       string            `json:"reason,omitempty"`
	TicketNumber string            `json:"ticket_number,omitempty"`
}

ChangeContext provides context information for a resource change

type ChangeTracker

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

ChangeTracker provides simple change tracking (compatibility with resource_tracker.go)

func NewChangeTracker

func NewChangeTracker(ctx *ChangeContext) *ChangeTracker

NewChangeTracker creates a new change tracker

func (*ChangeTracker) GetChanges

func (ct *ChangeTracker) GetChanges() []*ResourceChange

GetChanges returns all tracked changes

func (*ChangeTracker) GetChangesByObject

func (ct *ChangeTracker) GetChangesByObject(objectKey string) []*ResourceChange

GetChangesByObject returns changes for a specific object

func (*ChangeTracker) TrackStatement

func (ct *ChangeTracker) TrackStatement(stmt *types.Statement, migrationFile string) *ResourceChange

TrackStatement tracks a statement as a resource change

type CircularDependencyRiskRule

type CircularDependencyRiskRule struct{}

CircularDependencyRiskRule evaluates circular dependency risks

func (*CircularDependencyRiskRule) Description

func (r *CircularDependencyRiskRule) Description() string

func (*CircularDependencyRiskRule) Evaluate

func (r *CircularDependencyRiskRule) Evaluate(event *LifecycleEvent, lifecycle *ObjectLifecycle) RiskLevel

type ColumnEvolutionInfo

type ColumnEvolutionInfo struct {
	TableName    string   `json:"table_name"`
	OriginalName string   `json:"original_name"`
	FinalName    string   `json:"final_name"`
	RenameChain  []string `json:"rename_chain"` // All intermediate names
}

ColumnEvolutionInfo tracks how a column evolved through its lifecycle

type ColumnInfo

type ColumnInfo struct {
	Name         string   `json:"name"`
	DataType     string   `json:"data_type"`
	IsNullable   bool     `json:"is_nullable"`
	DefaultValue *string  `json:"default_value,omitempty"`
	IsIdentity   bool     `json:"is_identity"`
	IsGenerated  bool     `json:"is_generated"`
	Comment      string   `json:"comment,omitempty"`
	Ordinal      int      `json:"ordinal"`
	Constraints  []string `json:"constraints,omitempty"`
	Properties   any      `json:"properties,omitempty"`
}

ColumnInfo contains information about a table column

type ColumnTypeInfo

type ColumnTypeInfo struct {
	TableName  string
	ColumnName string
	DataType   string // Full type name (e.g., "double precision[]", "point", "geometry")
	IsArray    bool   // True if column is an array type
	IsSpatial  bool   // True if column is an actual spatial type (point, geography, geometry, etc.)
}

ColumnTypeInfo tracks column types for index optimization

type ConsolidationEngine

type ConsolidationEngine interface {
	GetTracker() *Tracker
	GetConfig() any // This would be the actual config type
}

ConsolidationEngine interface for the engine that applies consolidation rules

type ConsolidationResult

type ConsolidationResult struct {
	OriginalStatements []types.Statement `json:"original_statements"`
	ConsolidatedSQL    string            `json:"consolidated_sql"`
	Optimizations      []string          `json:"optimizations"`
	Warnings           []string          `json:"warnings"`
	RiskLevel          RiskLevel         `json:"risk_level"`
	EstimatedSavings   SquashSavings     `json:"estimated_savings"`
	// Column evolution tracking for data operation rewriting
	ColumnEvolutions map[string]*ColumnEvolutionInfo `json:"column_evolutions,omitempty"`
}

ConsolidationResult stores the result of object consolidation

type ConsolidationRule

type ConsolidationRule interface {
	CanApply(lifecycle *ObjectLifecycle) bool
	Apply(lifecycle *ObjectLifecycle, engine ConsolidationEngine) (*ConsolidationResult, error)
	Risk() RiskLevel
}

ConsolidationRule interface for consolidation rules used by the squasher

type ConstraintInfo

type ConstraintInfo struct {
	Name              string   `json:"name"`
	Schema            string   `json:"schema"`
	Table             string   `json:"table"`
	Type              string   `json:"type"`
	Columns           []string `json:"columns"`
	ReferencedTable   string   `json:"referenced_table,omitempty"`
	ReferencedColumns []string `json:"referenced_columns,omitempty"`
	Definition        string   `json:"definition"`
	IsDeferrable      bool     `json:"is_deferrable"`
	IsDeferred        bool     `json:"is_deferred"`
}

ConstraintInfo contains information about a database constraint

type ConstraintModificationRiskRule

type ConstraintModificationRiskRule struct{}

ConstraintModificationRiskRule evaluates risks from constraint modifications

func (*ConstraintModificationRiskRule) Description

func (r *ConstraintModificationRiskRule) Description() string

func (*ConstraintModificationRiskRule) Evaluate

type CrossSchemaRiskRule

type CrossSchemaRiskRule struct{}

CrossSchemaRiskRule evaluates cross-schema dependency risks

func (*CrossSchemaRiskRule) Description

func (r *CrossSchemaRiskRule) Description() string

func (*CrossSchemaRiskRule) Evaluate

func (r *CrossSchemaRiskRule) Evaluate(event *LifecycleEvent, lifecycle *ObjectLifecycle) RiskLevel

type CycleDetectionConfig

type CycleDetectionConfig struct {
	EnableDeepScan         bool // Perform deep analysis of cycles
	EnableDependencyTrack  bool // Track cross-object dependencies
	EnableVersionDetection bool // Detect object versioning patterns
	MaxCycleDepth          int  // Maximum depth to analyze
	MinCycleLength         int  // Minimum operations to consider a cycle
}

CycleDetectionConfig configures the cycle detection behavior

type CycleSeverity

type CycleSeverity string

CycleSeverity indicates how problematic a cycle is

const (
	SeverityLow      CycleSeverity = "LOW"      // Can be safely optimized
	SeverityMedium   CycleSeverity = "MEDIUM"   // Requires careful handling
	SeverityHigh     CycleSeverity = "HIGH"     // Potentially problematic
	SeverityCritical CycleSeverity = "CRITICAL" // Must be preserved as-is
)

type DDLCycle

type DDLCycle struct {
	Type          DDLCycleType        `json:"type"`
	Objects       []string            `json:"objects"`
	Operations    []DDLCycleOperation `json:"operations"`
	StartSequence int                 `json:"start_sequence"`
	EndSequence   int                 `json:"end_sequence"`
	Severity      CycleSeverity       `json:"severity"`
	CanOptimize   bool                `json:"can_optimize"`
	Description   string              `json:"description"`
	Dependencies  []string            `json:"dependencies,omitempty"`
}

DDLCycle represents a detected DDL cycle

type DDLCycleOperation

type DDLCycleOperation struct {
	Sequence  int       `json:"sequence"`
	Operation string    `json:"operation"`
	Object    string    `json:"object"`
	SQL       string    `json:"sql"`
	Timestamp time.Time `json:"timestamp"`
}

DDLCycleOperation represents an operation within a cycle

type DDLCycleType

type DDLCycleType string

DDLCycleType represents different types of DDL cycles that can be detected

const (
	SimpleCycle     DDLCycleType = "SIMPLE"     // A->B->A
	ComplexCycle    DDLCycleType = "COMPLEX"    // A->B->C->A
	DependencyCycle DDLCycleType = "DEPENDENCY" // Circular dependencies
	TransientCycle  DDLCycleType = "TRANSIENT"  // Object created and destroyed
	VersioningCycle DDLCycleType = "VERSIONING" // Object recreated with versions
	ConstraintCycle DDLCycleType = "CONSTRAINT" // Constraint dependencies
)

type DataLossRiskRule

type DataLossRiskRule struct{}

DataLossRiskRule evaluates risk of data loss

func (*DataLossRiskRule) Description

func (r *DataLossRiskRule) Description() string

func (*DataLossRiskRule) Evaluate

func (r *DataLossRiskRule) Evaluate(event *LifecycleEvent, lifecycle *ObjectLifecycle) RiskLevel

type DataOperation

type DataOperation struct {
	Statement    types.Statement  // Original statement with ParseTree for AST analysis
	Sequence     int              // Migration sequence number (for ordering)
	Index        int              // Statement index within migration (for ordering)
	Table        string           // Target table name (extracted from AST)
	Operation    types.Operation  // INSERT, UPDATE, or DELETE
	DependsOn    []string         // Tables this operation depends on (extracted from AST)
	ReferencedBy []*DataOperation // Operations that reference this one (for dependency graph)
}

DataOperation represents a single data operation (INSERT/UPDATE/DELETE) with dependency tracking

type DataOperationTracker

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

DataOperationTracker tracks all data operations separately from DDL object lifecycles

Design Decision: Data operations are fundamentally different from schema objects: - Schema objects have lifecycles (CREATE → ALTER → DROP) - Data operations are one-time mutations without lifecycle - Data ops must preserve sequence and have different dependency rules

Therefore, we track them separately using AST-based dependency extraction.

func NewDataOperationTracker

func NewDataOperationTracker() *DataOperationTracker

NewDataOperationTracker creates a new data operation tracker

func (*DataOperationTracker) AddOperation

func (dot *DataOperationTracker) AddOperation(stmt types.Statement, sequence int, index int) error

AddOperation adds a data operation to the tracker with AST-based dependency extraction

func (*DataOperationTracker) GetSortedOperations

func (dot *DataOperationTracker) GetSortedOperations() []*DataOperation

GetSortedOperations returns all data operations sorted by dependencies

Sorting Algorithm: 1. Within same table: INSERT before UPDATE before DELETE 2. Cross-table: topological sort by foreign key dependencies 3. Preserve original sequence when no dependencies exist

func (*DataOperationTracker) GetStatistics

func (dot *DataOperationTracker) GetStatistics() map[string]any

GetStatistics returns statistics about tracked data operations

type DatabaseMetadata

type DatabaseMetadata struct {
	Schemas    map[string]*SchemaInfo    `json:"schemas"`
	SearchPath []string                  `json:"search_path"`
	Version    string                    `json:"version"`
	Extensions map[string]*ExtensionInfo `json:"extensions"`
	Settings   map[string]string         `json:"settings"`
	Cache      *MetadataCache            `json:"-"`
}

DatabaseMetadata contains metadata about the database structure

type DependencyGraph

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

DependencyGraph manages object dependencies with cycle detection

func NewDependencyGraph

func NewDependencyGraph() *DependencyGraph

NewDependencyGraph creates a new dependency graph

func (*DependencyGraph) AddEdge

func (dg *DependencyGraph) AddEdge(from, to ObjectID)

AddEdge adds a dependency edge to the graph

func (*DependencyGraph) AddNode

func (dg *DependencyGraph) AddNode(objectID ObjectID)

AddNode adds a node to the dependency graph

func (*DependencyGraph) DetectCycles

func (dg *DependencyGraph) DetectCycles() [][]ObjectID

DetectCycles detects circular dependencies in the graph

func (*DependencyGraph) GetAllNodes

func (dg *DependencyGraph) GetAllNodes() map[ObjectID]*DependencyNode

GetAllNodes returns all nodes in the graph

func (*DependencyGraph) GetDependencyChain

func (dg *DependencyGraph) GetDependencyChain(objectID ObjectID) []ObjectID

GetDependencyChain returns the dependency chain for an object

func (*DependencyGraph) GetLevelOrder

func (dg *DependencyGraph) GetLevelOrder() [][]ObjectID

GetLevelOrder returns objects grouped by dependency level

func (*DependencyGraph) GetNode

func (dg *DependencyGraph) GetNode(objectID ObjectID) *DependencyNode

GetNode returns a dependency node by ID

func (*DependencyGraph) HasCycles

func (dg *DependencyGraph) HasCycles() bool

HasCycles returns true if the graph contains cycles

func (*DependencyGraph) IsEmpty

func (dg *DependencyGraph) IsEmpty() bool

IsEmpty returns true if the graph has no nodes

func (*DependencyGraph) RemoveNode

func (dg *DependencyGraph) RemoveNode(objectID ObjectID)

RemoveNode removes a node and all its edges from the graph

func (*DependencyGraph) Size

func (dg *DependencyGraph) Size() int

Size returns the number of nodes in the graph

func (*DependencyGraph) TopologicalSort

func (dg *DependencyGraph) TopologicalSort() ([]ObjectID, error)

TopologicalSort performs topological sorting of the dependency graph

type DependencyNode

type DependencyNode struct {
	ID           ObjectID
	Dependencies []ObjectID
	Dependents   []ObjectID
	Level        int  // Topological level
	InCycle      bool // Whether this node is part of a dependency cycle
}

DependencyNode represents a node in the dependency graph

type DependencyType

type DependencyType string

DependencyType represents different types of dependencies

const (
	DependencyTypeForeignKey  DependencyType = "FOREIGN_KEY"
	DependencyTypeFunction    DependencyType = "FUNCTION"
	DependencyTypeView        DependencyType = "VIEW"
	DependencyTypeType        DependencyType = "TYPE"
	DependencyTypeTrigger     DependencyType = "TRIGGER"
	DependencyTypeConstraint  DependencyType = "CONSTRAINT"
	DependencyTypeSequence    DependencyType = "SEQUENCE"
	DependencyTypeExtension   DependencyType = "EXTENSION"
	DependencyTypeCrossSchema DependencyType = "CROSS_SCHEMA"
	DependencyTypeColumn      DependencyType = "COLUMN"
)

type ExtensionInfo

type ExtensionInfo struct {
	Name        string `json:"name"`
	Schema      string `json:"schema"`
	Version     string `json:"version"`
	Relocatable bool   `json:"relocatable"`
	Comment     string `json:"comment,omitempty"`
}

ExtensionInfo contains information about a database extension

type FunctionInfo

type FunctionInfo struct {
	Name         string          `json:"name"`
	Schema       string          `json:"schema"`
	Owner        string          `json:"owner"`
	Comment      string          `json:"comment,omitempty"`
	Language     string          `json:"language"`
	ReturnType   string          `json:"return_type"`
	Parameters   []ParameterInfo `json:"parameters"`
	Definition   string          `json:"definition"`
	Volatility   string          `json:"volatility"`
	IsStrict     bool            `json:"is_strict"`
	IsSecDefiner bool            `json:"is_sec_definer"`
	Properties   map[string]any  `json:"properties,omitempty"`
}

FunctionInfo contains information about a database function

type IndexInfo

type IndexInfo struct {
	Name       string   `json:"name"`
	Schema     string   `json:"schema"`
	Table      string   `json:"table"`
	Columns    []string `json:"columns"`
	IsUnique   bool     `json:"is_unique"`
	IsPrimary  bool     `json:"is_primary"`
	IsPartial  bool     `json:"is_partial"`
	Method     string   `json:"method"`
	Definition string   `json:"definition"`
	Size       int64    `json:"size,omitempty"`
}

IndexInfo contains information about a database index

type LifecycleEvent

type LifecycleEvent struct {
	ID           string // Unique event identifier
	Migration    string
	Sequence     int
	Operation    types.Operation
	Statement    types.Statement
	Timestamp    time.Time        // When this event occurred
	Context      OperationContext // Enhanced context
	HasDataOps   bool
	Dependencies []string     // Dependencies at this point in time
	RiskLevel    RiskLevel    // Risk assessment for this operation
	SourceRange  *SourceRange // Source location information
}

LifecycleEvent represents an event in an object's lifecycle with enhanced context

type MemoryOptimizedTracker

type MemoryOptimizedTracker struct {
	*StreamingTracker
	// contains filtered or unexported fields
}

MemoryOptimizedTracker provides a simplified interface for memory-constrained environments

func NewMemoryOptimizedTracker

func NewMemoryOptimizedTracker(memoryLimitMB int, batchSize int) *MemoryOptimizedTracker

NewMemoryOptimizedTracker creates a tracker optimized for low memory usage

func (*MemoryOptimizedTracker) ProcessWithMemoryConstraints

func (mot *MemoryOptimizedTracker) ProcessWithMemoryConstraints(dir string) error

ProcessWithMemoryConstraints processes migrations with strict memory constraints

type MetadataCache

type MetadataCache struct {
	LastUpdated time.Time     `json:"last_updated"`
	TTL         time.Duration `json:"ttl"`
	Enabled     bool          `json:"enabled"`
}

MetadataCache provides caching for database metadata

type ObjectDependency

type ObjectDependency struct {
	ObjectID       ObjectID       `json:"object_id"`
	DependsOn      ObjectID       `json:"depends_on"`
	DependencyType DependencyType `json:"dependency_type"`
	IsRequired     bool           `json:"is_required"`
	Context        string         `json:"context,omitempty"`
}

ObjectDependency provides enhanced dependency tracking

type ObjectID

type ObjectID struct {
	Type   types.ObjectType `json:"type"`
	Schema string           `json:"schema"`
	Name   string           `json:"name"`
}

ObjectID provides comprehensive object identification

func (ObjectID) String

func (oid ObjectID) String() string

String returns string representation of ObjectID

type ObjectInfo

type ObjectInfo struct {
	Name       string         `json:"name"`
	Schema     string         `json:"schema"`
	Type       ResourceType   `json:"type"`
	Parent     *ObjectInfo    `json:"parent,omitempty"`
	Children   []*ObjectInfo  `json:"children,omitempty"`
	Properties map[string]any `json:"properties,omitempty"`
}

ObjectInfo represents information about a database object

func (*ObjectInfo) FullName

func (oi *ObjectInfo) FullName() string

FullName returns the fully qualified name

func (*ObjectInfo) String

func (oi *ObjectInfo) String() string

String returns a string representation of the object

type ObjectLifecycle

type ObjectLifecycle struct {
	Key          string // schema.name.type
	Name         string
	Schema       string
	Type         types.ObjectType
	History      []LifecycleEvent
	Permissions  []PermissionEvent
	Dependencies []ObjectDependency
	Category     types.Category
	WasDropped   bool

	// Analysis results
	IsRedundant   bool
	CanBeSquashed bool
	RiskLevel     RiskLevel

	// Metadata integration
	Metadata     ObjectMetadata
	CreatedAt    time.Time
	LastModified time.Time

	// Consolidation state
	ConsolidationResult *ConsolidationResult

	// Resource change tracking
	ResourceChanges []*ResourceChange
}

ObjectLifecycle tracks complete database object lifecycle with advanced metadata integration

func (*ObjectLifecycle) CanSquash

func (obj *ObjectLifecycle) CanSquash() bool

CanSquash determines if an object's lifecycle can be safely squashed

func (*ObjectLifecycle) GetAlterStatements

func (obj *ObjectLifecycle) GetAlterStatements() []types.Statement

GetAlterStatements returns all unique ALTER statements for the object (used for tables with column additions)

func (*ObjectLifecycle) GetConsolidatedPermissions

func (obj *ObjectLifecycle) GetConsolidatedPermissions() []PermissionEvent

GetConsolidatedPermissions returns the final permission state for an object

func (*ObjectLifecycle) GetFinalState

func (obj *ObjectLifecycle) GetFinalState() *types.Statement

GetFinalState returns the final state of the object For tables, this returns the CREATE statement, not ALTER statements

func (*ObjectLifecycle) GetHighestRiskLevel

func (obj *ObjectLifecycle) GetHighestRiskLevel() RiskLevel

GetHighestRiskLevel returns the highest risk level in the lifecycle

func (*ObjectLifecycle) GetPermissionStatements

func (obj *ObjectLifecycle) GetPermissionStatements() []types.Statement

GetPermissionStatements returns consolidated GRANT statements for this object

func (*ObjectLifecycle) HasConflicts

func (obj *ObjectLifecycle) HasConflicts() bool

HasConflicts checks for conflicting operations

type ObjectMetadata

type ObjectMetadata struct {
	Source       string   `json:"source"` // Migration file source
	Description  string   `json:"description"`
	Tags         []string `json:"tags"`
	DatabaseMeta any      `json:"database_meta"` // From metadata manager
}

ObjectMetadata stores metadata about database objects

type OperationContext

type OperationContext struct {
	MigrationFile   string          `json:"migration_file"`
	LineNumber      int             `json:"line_number"`
	PreConditions   map[string]bool `json:"pre_conditions"`
	PostConditions  map[string]bool `json:"post_conditions"`
	ConflictsWith   []string        `json:"conflicts_with"`
	RequiredObjects []ObjectID      `json:"required_objects"`
}

OperationContext provides context for lifecycle events

type ParameterInfo

type ParameterInfo struct {
	Name     string `json:"name"`
	DataType string `json:"data_type"`
	Mode     string `json:"mode"` // IN, OUT, INOUT
	Default  string `json:"default,omitempty"`
}

ParameterInfo contains information about function parameters

type PermissionChangeRiskRule

type PermissionChangeRiskRule struct{}

PermissionChangeRiskRule evaluates risks from permission changes

func (*PermissionChangeRiskRule) Description

func (r *PermissionChangeRiskRule) Description() string

func (*PermissionChangeRiskRule) Evaluate

func (r *PermissionChangeRiskRule) Evaluate(event *LifecycleEvent, lifecycle *ObjectLifecycle) RiskLevel

type PermissionEvent

type PermissionEvent struct {
	Operation types.Operation // GRANT or REVOKE
	Grantee   string
	Privilege string
	Statement types.Statement
}

PermissionEvent tracks GRANT/REVOKE operations

type ProductionUsageRiskRule

type ProductionUsageRiskRule struct{}

ProductionUsageRiskRule evaluates production usage risks

func (*ProductionUsageRiskRule) Description

func (r *ProductionUsageRiskRule) Description() string

func (*ProductionUsageRiskRule) Evaluate

func (r *ProductionUsageRiskRule) Evaluate(event *LifecycleEvent, lifecycle *ObjectLifecycle) RiskLevel

type RedundancyPattern

type RedundancyPattern string

RedundancyPattern identifies types of redundancy

const (
	PatternCreateAlterSequence RedundancyPattern = "CREATE_ALTER_SEQUENCE"
	PatternDropCreateSequence  RedundancyPattern = "DROP_CREATE_SEQUENCE"
	PatternDuplicateOperations RedundancyPattern = "DUPLICATE_OPERATIONS"
	PatternUnusedObject        RedundancyPattern = "UNUSED_OBJECT"
	PatternDuplicateComments   RedundancyPattern = "DUPLICATE_COMMENTS"
	PatternRedundantDoBlocks   RedundancyPattern = "REDUNDANT_DO_BLOCKS"
	PatternDuplicateIndexes    RedundancyPattern = "DUPLICATE_INDEXES"
)

type RedundancyReport

type RedundancyReport struct {
	Object      string
	Type        types.ObjectType
	Pattern     RedundancyPattern
	CanSquash   bool
	Explanation string
	Events      []LifecycleEvent
	Savings     SquashSavings
}

RedundancyReport provides analysis of redundant operations

type ResourceChange

type ResourceChange struct {
	ID           string             `json:"id"`
	Type         ResourceChangeType `json:"type"`
	Object       *ObjectInfo        `json:"object"`
	Range        *SourceRange       `json:"range"`
	Context      *ChangeContext     `json:"context"`
	Dependencies []string           `json:"dependencies,omitempty"`
	Metadata     map[string]any     `json:"metadata,omitempty"`
	Timestamp    time.Time          `json:"timestamp"`
	Migration    string             `json:"migration"`
	Statement    *types.Statement   `json:"statement,omitempty"`
}

ResourceChange represents a tracked change to a database resource

type ResourceChangeType

type ResourceChangeType string

ResourceChangeType represents the type of resource change

const (
	ResourceChangeCreate ResourceChangeType = "CREATE"
	ResourceChangeAlter  ResourceChangeType = "ALTER"
	ResourceChangeDrop   ResourceChangeType = "DROP"
	ResourceChangeRename ResourceChangeType = "RENAME"
	ResourceChangeMove   ResourceChangeType = "MOVE"
	ResourceChangeData   ResourceChangeType = "DATA"
	ResourceChangeGrant  ResourceChangeType = "GRANT"
	ResourceChangeRevoke ResourceChangeType = "REVOKE"
)

type ResourceType

type ResourceType = types.ObjectType

ResourceType represents the type of database resource - use types.ObjectType for consistency

type RiskAssessment

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

RiskAssessment evaluates risks for lifecycle operations

func NewRiskAssessment

func NewRiskAssessment() *RiskAssessment

NewRiskAssessment creates a new risk assessment with default rules

func (*RiskAssessment) AddRule

func (ra *RiskAssessment) AddRule(rule RiskRule)

AddRule adds a risk assessment rule

func (*RiskAssessment) Evaluate

func (ra *RiskAssessment) Evaluate(event *LifecycleEvent, lifecycle *ObjectLifecycle) RiskLevel

Evaluate assesses the risk level for a lifecycle event

func (*RiskAssessment) GetRiskRules

func (ra *RiskAssessment) GetRiskRules() []RiskRule

GetRiskRules returns all configured risk rules

type RiskLevel

type RiskLevel string

RiskLevel represents the risk level of operations

const (
	RiskLevelLow      RiskLevel = "LOW"
	RiskLevelMedium   RiskLevel = "MEDIUM"
	RiskLevelHigh     RiskLevel = "HIGH"
	RiskLevelCritical RiskLevel = "CRITICAL"
)

type RiskRule

type RiskRule interface {
	Evaluate(event *LifecycleEvent, lifecycle *ObjectLifecycle) RiskLevel
	Description() string
}

RiskRule defines a rule for risk assessment

type SchemaInfo

type SchemaInfo struct {
	Name        string                     `json:"name"`
	Owner       string                     `json:"owner"`
	Comment     string                     `json:"comment,omitempty"`
	Tables      map[string]*TableInfo      `json:"tables,omitempty"`
	Views       map[string]*ViewInfo       `json:"views,omitempty"`
	Functions   map[string]*FunctionInfo   `json:"functions,omitempty"`
	Indexes     map[string]*IndexInfo      `json:"indexes,omitempty"`
	Constraints map[string]*ConstraintInfo `json:"constraints,omitempty"`
	Sequences   map[string]*SequenceInfo   `json:"sequences,omitempty"`
	Types       map[string]*TypeInfo       `json:"types,omitempty"`
}

SchemaInfo contains information about a database schema

type SequenceInfo

type SequenceInfo struct {
	Name        string `json:"name"`
	Schema      string `json:"schema"`
	Owner       string `json:"owner"`
	Comment     string `json:"comment,omitempty"`
	DataType    string `json:"data_type"`
	StartValue  int64  `json:"start_value"`
	MinValue    *int64 `json:"min_value,omitempty"`
	MaxValue    *int64 `json:"max_value,omitempty"`
	Increment   int64  `json:"increment"`
	CycleOption bool   `json:"cycle_option"`
	CacheSize   int64  `json:"cache_size"`
	LastValue   int64  `json:"last_value"`
}

SequenceInfo contains information about a database sequence

type SourceRange

type SourceRange struct {
	Filename  string `json:"filename"`
	StartLine int    `json:"start_line"`
	EndLine   int    `json:"end_line"`
	StartCol  int    `json:"start_col"`
	EndCol    int    `json:"end_col"`
	Text      string `json:"text"`
	Context   string `json:"context,omitempty"`
}

SourceRange represents the source location of a change

type SquashSavings

type SquashSavings struct {
	StatementsReduced int
	FilesAffected     int
	LinesReduced      int
}

SquashSavings quantifies potential savings from squashing

type StreamingStats

type StreamingStats struct {
	MigrationsProcessed        int64   `json:"migrations_processed"`
	ObjectsTracked             int64   `json:"objects_tracked"`
	EventsCreated              int64   `json:"events_created"`
	ProcessingTime             int64   `json:"processing_time_ms"`
	ThroughputMigrationsPerSec float64 `json:"throughput_migrations_per_sec"`
}

StreamingStats tracks streaming processing statistics

type StreamingTracker

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

StreamingTracker integrates UnifiedTracker with performance streaming capabilities

func NewStreamingTracker

func NewStreamingTracker(batchSize, workerCount int, memManager *performance.MemoryManager) *StreamingTracker

NewStreamingTracker creates a new streaming tracker with performance integration

func (*StreamingTracker) GetCombinedStats

func (st *StreamingTracker) GetCombinedStats() (StreamingStats, performance.ProcessingStats)

GetCombinedStats returns both streaming and processing statistics

func (*StreamingTracker) GetStreamingStats

func (st *StreamingTracker) GetStreamingStats() StreamingStats

GetStreamingStats returns current streaming statistics

func (*StreamingTracker) GetTracker

func (st *StreamingTracker) GetTracker() *UnifiedTracker

GetTracker returns the underlying unified tracker

func (*StreamingTracker) ProcessDirectory

func (st *StreamingTracker) ProcessDirectory(dir string) error

ProcessDirectory processes all migrations in a directory using streaming

func (*StreamingTracker) SetProgressCallback

func (st *StreamingTracker) SetProgressCallback(callback func(processed, total int64, throughput float64))

SetProgressCallback sets a callback function for progress updates

func (*StreamingTracker) Stop

func (st *StreamingTracker) Stop() error

Stop gracefully stops the streaming tracker

type TableInfo

type TableInfo struct {
	Name        string                     `json:"name"`
	Schema      string                     `json:"schema"`
	Owner       string                     `json:"owner"`
	Comment     string                     `json:"comment,omitempty"`
	Tablespace  string                     `json:"tablespace,omitempty"`
	Columns     map[string]*ColumnInfo     `json:"columns"`
	Constraints map[string]*ConstraintInfo `json:"constraints"`
	Indexes     map[string]*IndexInfo      `json:"indexes"`
	Triggers    map[string]*TriggerInfo    `json:"triggers"`
	RowCount    int64                      `json:"row_count,omitempty"`
	Size        int64                      `json:"size,omitempty"`
}

TableInfo contains information about a database table

type Tracker

type Tracker = UnifiedTracker

Tracker is an alias for UnifiedTracker to maintain API compatibility

func NewTracker

func NewTracker() *Tracker

NewTracker creates a new unified tracker (alias for NewUnifiedTracker)

func NewTrackerWithMetadata

func NewTrackerWithMetadata(metaMgr *metadata.MetadataManager) *Tracker

NewTrackerWithMetadata creates a tracker with metadata manager integration

type TrackerStats

type TrackerStats struct {
	TotalObjects      int
	TotalMigrations   int
	TotalStatements   int
	TotalDependencies int
	DataOperations    int
	Inserts           int
	Updates           int
	Deletes           int
	ResourceChanges   int
	ObjectsByType     map[types.ObjectType]int
	ObjectsByCategory map[types.Category]int
	ChangesByType     map[ResourceChangeType]int
}

TrackerStats provides comprehensive tracking statistics

type TrackingResult

type TrackingResult struct {
	Migration     *types.Migration
	ObjectsAdded  int
	EventsCreated int
	ProcessTime   time.Duration
	MemoryUsed    int64
}

TrackingResult represents the result of processing a migration through streaming tracking

type TriggerInfo

type TriggerInfo struct {
	Name        string   `json:"name"`
	Schema      string   `json:"schema"`
	Table       string   `json:"table"`
	Events      []string `json:"events"`
	Timing      string   `json:"timing"`
	Orientation string   `json:"orientation"`
	Condition   string   `json:"condition,omitempty"`
	Definition  string   `json:"definition"`
	IsEnabled   bool     `json:"is_enabled"`
}

TriggerInfo contains information about a database trigger

type TypeInfo

type TypeInfo struct {
	Name       string         `json:"name"`
	Schema     string         `json:"schema"`
	Owner      string         `json:"owner"`
	Comment    string         `json:"comment,omitempty"`
	Type       string         `json:"type"` // enum, composite, domain, etc.
	Definition string         `json:"definition"`
	Properties map[string]any `json:"properties,omitempty"`
}

TypeInfo contains information about a user-defined type

type UnifiedTracker

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

UnifiedTracker provides comprehensive object lifecycle tracking with advanced metadata integration

func NewUnifiedTracker

func NewUnifiedTracker() *UnifiedTracker

NewUnifiedTracker creates a comprehensive tracker with all features

func NewUnifiedTrackerWithMetadata

func NewUnifiedTrackerWithMetadata(metaMgr *metadata.MetadataManager) *UnifiedTracker

NewUnifiedTrackerWithMetadata creates a tracker with metadata manager integration

func (*UnifiedTracker) ClearProcessedMigrations

func (ut *UnifiedTracker) ClearProcessedMigrations()

ClearProcessedMigrations removes migration references to free memory in streaming mode This should only be called when all necessary analysis is complete

func (*UnifiedTracker) DetectDDLCycles

func (ut *UnifiedTracker) DetectDDLCycles() error

DetectDDLCycles analyzes tracked objects for DDL cycles and stores results

func (*UnifiedTracker) DisableStreamingMode

func (ut *UnifiedTracker) DisableStreamingMode()

DisableStreamingMode disables streaming mode and restores full migration storage

func (*UnifiedTracker) EnableStreamingMode

func (ut *UnifiedTracker) EnableStreamingMode()

EnableStreamingMode enables streaming mode to reduce memory usage for large migration sets

func (*UnifiedTracker) ExtractColumnTypes

func (ut *UnifiedTracker) ExtractColumnTypes(tableName string, stmt *types.Statement)

ExtractColumnTypes extracts column type information from a CREATE TABLE statement

func (*UnifiedTracker) GetActualDependencyGraph

func (ut *UnifiedTracker) GetActualDependencyGraph() *DependencyGraph

GetActualDependencyGraph returns the actual dependency graph with full functionality

func (*UnifiedTracker) GetColumnType

func (ut *UnifiedTracker) GetColumnType(tableName, columnName string) *ColumnTypeInfo

GetColumnType retrieves column type information

func (*UnifiedTracker) GetCriticalCycles

func (ut *UnifiedTracker) GetCriticalCycles() []DDLCycle

GetCriticalCycles returns only critical DDL cycles

func (*UnifiedTracker) GetDependencyGraph

func (ut *UnifiedTracker) GetDependencyGraph() map[string][]string

GetDependencyGraph returns the dependency graph as a map for compatibility

func (*UnifiedTracker) GetDetectedCycles

func (ut *UnifiedTracker) GetDetectedCycles() []DDLCycle

GetDetectedCycles returns all detected DDL cycles

func (*UnifiedTracker) GetObjects

func (ut *UnifiedTracker) GetObjects() map[string]*ObjectLifecycle

GetObjects returns all tracked objects

func (*UnifiedTracker) GetObjectsByCategory

func (ut *UnifiedTracker) GetObjectsByCategory() map[types.Category][]*ObjectLifecycle

GetObjectsByCategory returns objects grouped by category

func (*UnifiedTracker) GetProcessingStats

func (ut *UnifiedTracker) GetProcessingStats() (processed, total int64)

GetProcessingStats returns processing statistics for streaming mode

func (*UnifiedTracker) GetRedundantObjects

func (ut *UnifiedTracker) GetRedundantObjects() []RedundancyReport

GetRedundantObjects analyzes objects for redundancy patterns

func (*UnifiedTracker) GetResourceChanges

func (ut *UnifiedTracker) GetResourceChanges() []*ResourceChange

GetResourceChanges returns all resource changes

func (*UnifiedTracker) GetResourceChangesByType

func (ut *UnifiedTracker) GetResourceChangesByType(changeType ResourceChangeType) []*ResourceChange

GetResourceChangesByType returns resource changes filtered by type

func (*UnifiedTracker) GetStatistics

func (ut *UnifiedTracker) GetStatistics() TrackerStats

GetStatistics returns comprehensive tracking statistics

func (*UnifiedTracker) HasDDLCycles

func (ut *UnifiedTracker) HasDDLCycles() bool

HasDDLCycles returns true if any DDL cycles were detected

func (*UnifiedTracker) IsObjectInCycle

func (ut *UnifiedTracker) IsObjectInCycle(objectKey string) bool

IsObjectInCycle checks if an object is part of any DDL cycle

func (*UnifiedTracker) IsStreamingMode

func (ut *UnifiedTracker) IsStreamingMode() bool

IsStreamingMode returns whether streaming mode is enabled

func (*UnifiedTracker) ProcessMigration

func (ut *UnifiedTracker) ProcessMigration(m *types.Migration, sequence int)

ProcessMigration processes a migration with comprehensive tracking

func (*UnifiedTracker) ValidateConsistency

func (ut *UnifiedTracker) ValidateConsistency() []string

ValidateConsistency checks for consistency issues in tracking

type ViewInfo

type ViewInfo struct {
	Name        string                 `json:"name"`
	Schema      string                 `json:"schema"`
	Owner       string                 `json:"owner"`
	Comment     string                 `json:"comment,omitempty"`
	Definition  string                 `json:"definition"`
	Columns     map[string]*ColumnInfo `json:"columns"`
	IsUpdatable bool                   `json:"is_updatable"`
}

ViewInfo contains information about a database view

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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