Skip to content

Commit c92dd62

Browse files
Add basic view support (#226)
1 parent 3944eea commit c92dd62

File tree

14 files changed

+1155
-69
lines changed

14 files changed

+1155
-69
lines changed

.sqlfluff

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[sqlfluff]
22
dialect = postgres
33
templater = placeholder
4+
large_file_skip_byte_limit = 0
45

56
[sqlfluff:templater:placeholder]
67
param_regex = sqlc.arg\(.*\)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Unsupported: <= 13 are not supported. Use at your own risk.
176176

177177
# Unsupported migrations
178178
An abridged list of unsupported migrations:
179-
- Views (Planned)
179+
- Materialized Views (Planned); Views **are** supported
180180
- Privileges (Planned)
181181
- Types (Only enums are currently supported)
182182
- Renaming. The diffing library relies on names to identify the old and new versions of a table, index, etc. If you rename

cmd/pg-schema-diff/datastructs.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
import (
44
"fmt"
55
"sort"
6+
7+
"github.com/stripe/pg-schema-diff/internal/util"
68
)
79

810
func mustGetAndDeleteKey(m map[string]string, key string) (string, error) {
@@ -15,10 +17,7 @@ func mustGetAndDeleteKey(m map[string]string, key string) (string, error) {
1517
}
1618

1719
func keys(m map[string]string) []string {
18-
var vals []string
19-
for k := range m {
20-
vals = append(vals, k)
21-
}
20+
vals := util.Keys(m)
2221
sort.Strings(vals)
2322
return vals
2423
}

cmd/pg-schema-diff/datastructs_test.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

internal/migration_acceptance_tests/schema_cases_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ var schemaAcceptanceTests = []acceptanceTestCase{
8989
RAISE NOTICE 'foobar';
9090
END;
9191
$$ LANGUAGE plpgsql;
92+
93+
CREATE VIEW schema_1.foobar_view AS
94+
SELECT id, foo, fizz
95+
FROM schema_1.foobar
96+
WHERE LENGTH(foo) > 10;
97+
98+
CREATE VIEW public_bar_view AS
99+
SELECT bar, foo, fizz, buzz
100+
FROM bar
101+
WHERE buzz > 0.5;
92102
`,
93103
},
94104
newSchemaDDL: []string{
@@ -170,6 +180,16 @@ var schemaAcceptanceTests = []acceptanceTestCase{
170180
RAISE NOTICE 'foobar';
171181
END;
172182
$$ LANGUAGE plpgsql;
183+
184+
CREATE VIEW schema_1.foobar_view AS
185+
SELECT id, foo, fizz
186+
FROM schema_1.foobar
187+
WHERE LENGTH(foo) > 10;
188+
189+
CREATE VIEW public_bar_view AS
190+
SELECT bar, foo, fizz, buzz
191+
FROM bar
192+
WHERE buzz > 0.5;
173193
`,
174194
},
175195
expectEmptyPlan: true,
@@ -360,6 +380,16 @@ var schemaAcceptanceTests = []acceptanceTestCase{
360380
BEFORE UPDATE ON schema_2.bar
361381
FOR EACH ROW
362382
EXECUTE FUNCTION check_content();
383+
384+
CREATE VIEW schema_2.new_table_view AS
385+
SELECT id, version, new_foo, new_bar
386+
FROM "New_table"
387+
WHERE version > 0;
388+
389+
CREATE VIEW schema_3.bar_summary AS
390+
SELECT fizz, buzz, COUNT(*) as count
391+
FROM schema_2.bar
392+
GROUP BY fizz, buzz;
363393
`,
364394
},
365395
expectedHazardTypes: []diff.MigrationHazardType{

0 commit comments

Comments
 (0)