Added diff to the tool
This commit is contained in:
192
pkg/diff/types.go
Normal file
192
pkg/diff/types.go
Normal file
@@ -0,0 +1,192 @@
|
||||
package diff
|
||||
|
||||
import "git.warky.dev/wdevs/relspecgo/pkg/models"
|
||||
|
||||
// DiffResult represents the complete difference analysis between two databases
|
||||
type DiffResult struct {
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
Schemas *SchemaDiff `json:"schemas"`
|
||||
}
|
||||
|
||||
// SchemaDiff represents differences at the schema level
|
||||
type SchemaDiff struct {
|
||||
Missing []*models.Schema `json:"missing"` // Schemas in source but not in target
|
||||
Extra []*models.Schema `json:"extra"` // Schemas in target but not in source
|
||||
Modified []*SchemaChange `json:"modified"` // Schemas that exist in both but differ
|
||||
}
|
||||
|
||||
// SchemaChange represents changes within a schema
|
||||
type SchemaChange struct {
|
||||
Name string `json:"name"`
|
||||
Tables *TableDiff `json:"tables,omitempty"`
|
||||
Views *ViewDiff `json:"views,omitempty"`
|
||||
Sequences *SequenceDiff `json:"sequences,omitempty"`
|
||||
}
|
||||
|
||||
// TableDiff represents differences in tables
|
||||
type TableDiff struct {
|
||||
Missing []*models.Table `json:"missing"` // Tables in source but not in target
|
||||
Extra []*models.Table `json:"extra"` // Tables in target but not in source
|
||||
Modified []*TableChange `json:"modified"` // Tables that exist in both but differ
|
||||
}
|
||||
|
||||
// TableChange represents changes within a table
|
||||
type TableChange struct {
|
||||
Name string `json:"name"`
|
||||
Schema string `json:"schema"`
|
||||
Columns *ColumnDiff `json:"columns,omitempty"`
|
||||
Indexes *IndexDiff `json:"indexes,omitempty"`
|
||||
Constraints *ConstraintDiff `json:"constraints,omitempty"`
|
||||
Relationships *RelationshipDiff `json:"relationships,omitempty"`
|
||||
}
|
||||
|
||||
// ColumnDiff represents differences in columns
|
||||
type ColumnDiff struct {
|
||||
Missing []*models.Column `json:"missing"` // Columns in source but not in target
|
||||
Extra []*models.Column `json:"extra"` // Columns in target but not in source
|
||||
Modified []*ColumnChange `json:"modified"` // Columns that exist in both but differ
|
||||
}
|
||||
|
||||
// ColumnChange represents a modified column
|
||||
type ColumnChange struct {
|
||||
Name string `json:"name"`
|
||||
Source *models.Column `json:"source"`
|
||||
Target *models.Column `json:"target"`
|
||||
Changes map[string]any `json:"changes"` // Map of field name to what changed
|
||||
}
|
||||
|
||||
// IndexDiff represents differences in indexes
|
||||
type IndexDiff struct {
|
||||
Missing []*models.Index `json:"missing"` // Indexes in source but not in target
|
||||
Extra []*models.Index `json:"extra"` // Indexes in target but not in source
|
||||
Modified []*IndexChange `json:"modified"` // Indexes that exist in both but differ
|
||||
}
|
||||
|
||||
// IndexChange represents a modified index
|
||||
type IndexChange struct {
|
||||
Name string `json:"name"`
|
||||
Source *models.Index `json:"source"`
|
||||
Target *models.Index `json:"target"`
|
||||
Changes map[string]any `json:"changes"`
|
||||
}
|
||||
|
||||
// ConstraintDiff represents differences in constraints
|
||||
type ConstraintDiff struct {
|
||||
Missing []*models.Constraint `json:"missing"` // Constraints in source but not in target
|
||||
Extra []*models.Constraint `json:"extra"` // Constraints in target but not in source
|
||||
Modified []*ConstraintChange `json:"modified"` // Constraints that exist in both but differ
|
||||
}
|
||||
|
||||
// ConstraintChange represents a modified constraint
|
||||
type ConstraintChange struct {
|
||||
Name string `json:"name"`
|
||||
Source *models.Constraint `json:"source"`
|
||||
Target *models.Constraint `json:"target"`
|
||||
Changes map[string]any `json:"changes"`
|
||||
}
|
||||
|
||||
// RelationshipDiff represents differences in relationships
|
||||
type RelationshipDiff struct {
|
||||
Missing []*models.Relationship `json:"missing"` // Relationships in source but not in target
|
||||
Extra []*models.Relationship `json:"extra"` // Relationships in target but not in source
|
||||
Modified []*RelationshipChange `json:"modified"` // Relationships that exist in both but differ
|
||||
}
|
||||
|
||||
// RelationshipChange represents a modified relationship
|
||||
type RelationshipChange struct {
|
||||
Name string `json:"name"`
|
||||
Source *models.Relationship `json:"source"`
|
||||
Target *models.Relationship `json:"target"`
|
||||
Changes map[string]any `json:"changes"`
|
||||
}
|
||||
|
||||
// ViewDiff represents differences in views
|
||||
type ViewDiff struct {
|
||||
Missing []*models.View `json:"missing"` // Views in source but not in target
|
||||
Extra []*models.View `json:"extra"` // Views in target but not in source
|
||||
Modified []*ViewChange `json:"modified"` // Views that exist in both but differ
|
||||
}
|
||||
|
||||
// ViewChange represents a modified view
|
||||
type ViewChange struct {
|
||||
Name string `json:"name"`
|
||||
Source *models.View `json:"source"`
|
||||
Target *models.View `json:"target"`
|
||||
Changes map[string]any `json:"changes"`
|
||||
}
|
||||
|
||||
// SequenceDiff represents differences in sequences
|
||||
type SequenceDiff struct {
|
||||
Missing []*models.Sequence `json:"missing"` // Sequences in source but not in target
|
||||
Extra []*models.Sequence `json:"extra"` // Sequences in target but not in source
|
||||
Modified []*SequenceChange `json:"modified"` // Sequences that exist in both but differ
|
||||
}
|
||||
|
||||
// SequenceChange represents a modified sequence
|
||||
type SequenceChange struct {
|
||||
Name string `json:"name"`
|
||||
Source *models.Sequence `json:"source"`
|
||||
Target *models.Sequence `json:"target"`
|
||||
Changes map[string]any `json:"changes"`
|
||||
}
|
||||
|
||||
// Summary provides counts for quick overview
|
||||
type Summary struct {
|
||||
Schemas SchemaSummary `json:"schemas"`
|
||||
Tables TableSummary `json:"tables"`
|
||||
Columns ColumnSummary `json:"columns"`
|
||||
Indexes IndexSummary `json:"indexes"`
|
||||
Constraints ConstraintSummary `json:"constraints"`
|
||||
Relationships RelationshipSummary `json:"relationships"`
|
||||
Views ViewSummary `json:"views"`
|
||||
Sequences SequenceSummary `json:"sequences"`
|
||||
}
|
||||
|
||||
type SchemaSummary struct {
|
||||
Missing int `json:"missing"`
|
||||
Extra int `json:"extra"`
|
||||
Modified int `json:"modified"`
|
||||
}
|
||||
|
||||
type TableSummary struct {
|
||||
Missing int `json:"missing"`
|
||||
Extra int `json:"extra"`
|
||||
Modified int `json:"modified"`
|
||||
}
|
||||
|
||||
type ColumnSummary struct {
|
||||
Missing int `json:"missing"`
|
||||
Extra int `json:"extra"`
|
||||
Modified int `json:"modified"`
|
||||
}
|
||||
|
||||
type IndexSummary struct {
|
||||
Missing int `json:"missing"`
|
||||
Extra int `json:"extra"`
|
||||
Modified int `json:"modified"`
|
||||
}
|
||||
|
||||
type ConstraintSummary struct {
|
||||
Missing int `json:"missing"`
|
||||
Extra int `json:"extra"`
|
||||
Modified int `json:"modified"`
|
||||
}
|
||||
|
||||
type RelationshipSummary struct {
|
||||
Missing int `json:"missing"`
|
||||
Extra int `json:"extra"`
|
||||
Modified int `json:"modified"`
|
||||
}
|
||||
|
||||
type ViewSummary struct {
|
||||
Missing int `json:"missing"`
|
||||
Extra int `json:"extra"`
|
||||
Modified int `json:"modified"`
|
||||
}
|
||||
|
||||
type SequenceSummary struct {
|
||||
Missing int `json:"missing"`
|
||||
Extra int `json:"extra"`
|
||||
Modified int `json:"modified"`
|
||||
}
|
||||
Reference in New Issue
Block a user