Skip to content

Commit f801b7f

Browse files
Remove ElseExpr and TestExpr from trigger templates (#651)
Remove two unused parts of the up/down trigger templates. These parts of the template are never set outside of tests; the extra functionality they provide is not needed.
1 parent f078a91 commit f801b7f

File tree

3 files changed

+1
-52
lines changed

3 files changed

+1
-52
lines changed

pkg/migrations/templates/function.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,8 @@ const Function = `CREATE OR REPLACE FUNCTION {{ .Name | qi }}()
1919
INTO search_path
2020
FROM current_setting('search_path');
2121
22-
IF search_path {{- if eq .Direction "up" }} != {{- else }} = {{- end }} {{ .LatestSchema | ql }} {{ if .TestExpr -}} AND {{ .TestExpr }} {{ end -}} THEN
22+
IF search_path {{- if eq .Direction "up" }} != {{- else }} = {{- end }} {{ .LatestSchema | ql }} THEN
2323
NEW.{{ .PhysicalColumn | qi }} = {{ .SQL }};
24-
{{- if .ElseExpr }}
25-
ELSE
26-
{{ .ElseExpr }};
27-
{{- end }}
2824
END IF;
2925
3026
RETURN NEW;

pkg/migrations/trigger.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ type triggerConfig struct {
2929
TableName string
3030
PhysicalColumn string
3131
LatestSchema string
32-
TestExpr string
33-
ElseExpr string
3432
SQL string
3533
}
3634

pkg/migrations/trigger_test.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -52,51 +52,6 @@ func TestBuildFunction(t *testing.T) {
5252
NEW."_pgroll_new_review" = product || 'is good';
5353
END IF;
5454
55-
RETURN NEW;
56-
END; $$
57-
`,
58-
},
59-
{
60-
name: "complete up trigger",
61-
config: triggerConfig{
62-
Name: "triggerName",
63-
Direction: TriggerDirectionUp,
64-
Columns: map[string]*schema.Column{
65-
"id": {Name: "id", Type: "int"},
66-
"username": {Name: "username", Type: "text"},
67-
"product": {Name: "product", Type: "text"},
68-
"review": {Name: "review", Type: "text"},
69-
},
70-
SchemaName: "public",
71-
LatestSchema: "public_01_migration_name",
72-
TableName: "reviews",
73-
TestExpr: `NEW."review" IS NULL`,
74-
PhysicalColumn: "_pgroll_new_review",
75-
ElseExpr: `NEW."_pgroll_new_review" = NEW."review"`,
76-
SQL: "product || 'is good'",
77-
},
78-
expected: `CREATE OR REPLACE FUNCTION "triggerName"()
79-
RETURNS TRIGGER
80-
LANGUAGE PLPGSQL
81-
AS $$
82-
DECLARE
83-
"id" "public"."reviews"."id"%TYPE := NEW."id";
84-
"product" "public"."reviews"."product"%TYPE := NEW."product";
85-
"review" "public"."reviews"."review"%TYPE := NEW."review";
86-
"username" "public"."reviews"."username"%TYPE := NEW."username";
87-
latest_schema text;
88-
search_path text;
89-
BEGIN
90-
SELECT current_setting
91-
INTO search_path
92-
FROM current_setting('search_path');
93-
94-
IF search_path != 'public_01_migration_name' AND NEW."review" IS NULL THEN
95-
NEW."_pgroll_new_review" = product || 'is good';
96-
ELSE
97-
NEW."_pgroll_new_review" = NEW."review";
98-
END IF;
99-
10055
RETURN NEW;
10156
END; $$
10257
`,

0 commit comments

Comments
 (0)