Skip to content

Commit

Permalink
feat: add more dependency headers
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 14, 2024
1 parent 8a1000f commit 82d8072
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
16 changes: 10 additions & 6 deletions migrate/dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package migrate
import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/onsi/gomega"
)

func TestParseDependencies(t *testing.T) {
Expand All @@ -25,25 +25,29 @@ func TestParseDependencies(t *testing.T) {
},
}

g := gomega.NewWithT(t) // use gomega with std go tests
for _, td := range testdata {
got, err := parseDependencies(td.script)
if err != nil {
t.Fatal(err.Error())
}

if diff := cmp.Diff(got, td.want); diff != "" {
t.Fatalf("%s", diff)
}
g.Expect(got).To(gomega.Equal(td.want))
}
}

func TestDependencyMap(t *testing.T) {
g := gomega.NewWithT(t) // use gomega with std go tests

graph, err := getDependencyTree()
if err != nil {
t.Fatal(err.Error())
}

if diff := cmp.Diff(graph["functions/drop.sql"], []string{"views/021_notification.sql"}); diff != "" {
t.Fatalf("%v", diff)
expected := map[string][]string{
"functions/drop.sql": {"views/006_config_views.sql", "views/021_notification.sql"},
"views/006_config_views.sql": {"views/021_notification.sql"},
}

g.Expect(graph).To(gomega.BeEquivalentTo(expected))
}
2 changes: 2 additions & 0 deletions views/006_config_views.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- dependsOn: functions/drop.sql

-- Add cascade drops first to make sure all functions and views are always recreated
DROP VIEW IF EXISTS configs CASCADE;

Expand Down
2 changes: 1 addition & 1 deletion views/021_notification.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- dependsOn: functions/drop.sql
-- dependsOn: functions/drop.sql, views/006_config_views.sql

-- Handle before updates for notifications
CREATE OR REPLACE FUNCTION reset_notification_error_before_update ()
Expand Down

0 comments on commit 82d8072

Please sign in to comment.