Skip to content

Commit

Permalink
Check model added
Browse files Browse the repository at this point in the history
  • Loading branch information
stefannegele committed Sep 22, 2023
1 parent 43d6879 commit bc6df8b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
20 changes: 20 additions & 0 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
DatasetDifferenceTypeFieldAdditionalConstraintAdded
DatasetDifferenceTypeFieldAdditionalConstraintRemoved
DatasetDifferenceDatasetSchemaTypeChanged
DatasetDifferenceModelAdded
)

func (d DatasetDifferenceType) String() string {
Expand All @@ -74,6 +75,8 @@ func (d DatasetDifferenceType) String() string {
// info
case DatasetDifferenceDatasetSchemaTypeChanged:
return "dataset-schema-type-changed"
case DatasetDifferenceModelAdded:
return "model-added"
}

return ""
Expand Down Expand Up @@ -132,6 +135,7 @@ func CompareDatasets(old, new Dataset) (result []DatasetDifference) {
fieldConstraintRemoved,
// info
datasetSchemaTypeChanged,
modelAdded,
}

for _, comparison := range comparisons {
Expand Down Expand Up @@ -309,6 +313,22 @@ func datasetSchemaTypeChanged(old, new Dataset) (result []DatasetDifference) {
return result
}

func modelAdded(old, new Dataset) (result []DatasetDifference) {
for _, newModel := range new.Models {
if newModel.findEquivalent(old.Models) == nil {
result = append(result, DatasetDifference{
Type: DatasetDifferenceModelAdded,
Level: DatasetDifferenceLevelModel,
Severity: DatasetDifferenceSeverityInfo,
ModelName: newModel.Name,
Description: fmt.Sprintf("model '%v' was added", newModel.Name),
})
}
}

return result
}

func (constraint FieldConstraint) isIn(list []FieldConstraint) bool {
for _, oldConstraint := range list {
if constraint.Type == oldConstraint.Type && constraint.Expression == oldConstraint.Expression {
Expand Down
14 changes: 14 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ func TestCompareDatasets(t *testing.T) {
Description: "schema type changed from 'dbt' to 'json-schema'",
}},
},
{
name: "modelAdded",
args: args{
Dataset{},
Dataset{Models: []Model{{Name: "my_model"}}},
},
want: []DatasetDifference{{
Type: DatasetDifferenceModelAdded,
Level: DatasetDifferenceLevelModel,
Severity: DatasetDifferenceSeverityInfo,
ModelName: "my_model",
Description: "model 'my_model' was added",
}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit bc6df8b

Please sign in to comment.