@@ -41,6 +41,21 @@ func TestBuildViewReloptionDiff(t *testing.T) {
4141` , out )
4242 })
4343
44+ t .Run ("emits RESET when all reloptions are removed" , func (t * testing.T ) {
45+ key := viewReloptionKey {schema : "public" , name : "user_details" , relkind : "v" }
46+ out := buildViewReloptionDiff (
47+ map [viewReloptionKey ][]string {
48+ key : {"security_invoker=true" , "check_option=local" },
49+ },
50+ map [viewReloptionKey ][]string {
51+ key : {},
52+ },
53+ []string {"public" },
54+ )
55+ assert .Equal (t , `ALTER VIEW "public"."user_details" RESET (check_option, security_invoker);
56+ ` , out )
57+ })
58+
4459 t .Run ("emits SET and RESET in stable order" , func (t * testing.T ) {
4560 key := viewReloptionKey {schema : "public" , name : "user_details" , relkind : "v" }
4661 out := buildViewReloptionDiff (
@@ -57,6 +72,21 @@ ALTER VIEW "public"."user_details" RESET (check_option);
5772` , out )
5873 })
5974
75+ t .Run ("batches multiple changed reloptions into one SET" , func (t * testing.T ) {
76+ key := viewReloptionKey {schema : "public" , name : "user_details" , relkind : "v" }
77+ out := buildViewReloptionDiff (
78+ map [viewReloptionKey ][]string {
79+ key : {"security_invoker=true" , "check_option=local" },
80+ },
81+ map [viewReloptionKey ][]string {
82+ key : {"security_invoker=false" , "check_option=cascaded" },
83+ },
84+ []string {"public" },
85+ )
86+ assert .Equal (t , `ALTER VIEW "public"."user_details" SET (check_option=cascaded, security_invoker=false);
87+ ` , out )
88+ })
89+
6090 t .Run ("emits ALTER MATERIALIZED VIEW for materialized views" , func (t * testing.T ) {
6191 key := viewReloptionKey {schema : "public" , name : "cached_details" , relkind : "m" }
6292 out := buildViewReloptionDiff (
@@ -84,6 +114,37 @@ ALTER VIEW "public"."user_details" RESET (check_option);
84114 assert .Empty (t , out )
85115 })
86116
117+ t .Run ("skips no-op diff when neither side has reloptions" , func (t * testing.T ) {
118+ key := viewReloptionKey {schema : "public" , name : "user_details" , relkind : "v" }
119+ out := buildViewReloptionDiff (
120+ map [viewReloptionKey ][]string {
121+ key : {},
122+ },
123+ map [viewReloptionKey ][]string {
124+ key : {},
125+ },
126+ []string {"public" },
127+ )
128+ assert .Empty (t , out )
129+ })
130+
131+ t .Run ("skips source-only dropped views" , func (t * testing.T ) {
132+ dropped := viewReloptionKey {schema : "public" , name : "dropped_view" , relkind : "v" }
133+ kept := viewReloptionKey {schema : "public" , name : "kept_view" , relkind : "v" }
134+ out := buildViewReloptionDiff (
135+ map [viewReloptionKey ][]string {
136+ dropped : {"security_invoker=true" },
137+ kept : {"security_invoker=true" },
138+ },
139+ map [viewReloptionKey ][]string {
140+ kept : {"security_invoker=false" },
141+ },
142+ []string {"public" },
143+ )
144+ assert .Equal (t , `ALTER VIEW "public"."kept_view" SET (security_invoker=false);
145+ ` , out )
146+ })
147+
87148 t .Run ("respects requested schema filter" , func (t * testing.T ) {
88149 key := viewReloptionKey {schema : "private" , name : "user_details" , relkind : "v" }
89150 out := buildViewReloptionDiff (
0 commit comments