Skip to content

Commit 4524cd4

Browse files
committed
Minor cleanup and output improvements
Former-commit-id: 436f011
1 parent fcf8acd commit 4524cd4

5 files changed

Lines changed: 23 additions & 28 deletions

File tree

grant-attribute.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,14 @@ func (c *GrantAttributeSchema) Compare(obj interface{}) int {
112112

113113
// Add prints SQL to add the column
114114
func (c *GrantAttributeSchema) Add() {
115-
fmt.Println("--Add")
116115
role, grants := parseGrants(c.get("attribute_acl"))
117-
fmt.Printf("GRANT %s (%s) ON %s TO %s;\n", strings.Join(grants, ", "), c.get("attribute_name"), c.get("relationship_name"), role)
116+
fmt.Printf("GRANT %s (%s) ON %s TO %s; -- Add\n", strings.Join(grants, ", "), c.get("attribute_name"), c.get("relationship_name"), role)
118117
}
119118

120119
// Drop prints SQL to drop the column
121120
func (c *GrantAttributeSchema) Drop() {
122-
fmt.Println("--Drop")
123121
role, grants := parseGrants(c.get("attribute_acl"))
124-
fmt.Printf("REVOKE %s (%s) ON %s FROM %s;\n", strings.Join(grants, ", "), c.get("attribute_name"), c.get("relationship_name"), role)
122+
fmt.Printf("REVOKE %s (%s) ON %s FROM %s; -- Drop\n", strings.Join(grants, ", "), c.get("attribute_name"), c.get("relationship_name"), role)
125123
}
126124

127125
// Change handles the case where the relationship and column match, but the details do not
@@ -130,7 +128,6 @@ func (c *GrantAttributeSchema) Change(obj interface{}) {
130128
if !ok {
131129
fmt.Println("-- Error!!!, Change needs a GrantAttributeSchema instance", c2)
132130
}
133-
fmt.Println("--Change")
134131

135132
role, grants1 := parseGrants(c.get("attribute_acl"))
136133
_, grants2 := parseGrants(c2.get("attribute_acl"))
@@ -144,7 +141,7 @@ func (c *GrantAttributeSchema) Change(obj interface{}) {
144141
}
145142
}
146143
if len(grantList) > 0 {
147-
fmt.Printf("GRANT %s (%s) ON %s TO %s;\n", strings.Join(grantList, ", "), c.get("attribute_name"), c.get("relationship_name"), role)
144+
fmt.Printf("GRANT %s (%s) ON %s TO %s; -- Change\n", strings.Join(grantList, ", "), c.get("attribute_name"), c.get("relationship_name"), role)
148145
}
149146

150147
// Find grants in the second db that are not in the first
@@ -156,7 +153,7 @@ func (c *GrantAttributeSchema) Change(obj interface{}) {
156153
}
157154
}
158155
if len(revokeList) > 0 {
159-
fmt.Printf("REVOKE %s (%s) ON %s FROM %s;\n", strings.Join(grantList, ", "), c.get("attribute_name"), c.get("relationship_name"), role)
156+
fmt.Printf("REVOKE %s (%s) ON %s FROM %s; -- Change\n", strings.Join(grantList, ", "), c.get("attribute_name"), c.get("relationship_name"), role)
160157
}
161158

162159
// fmt.Printf("--1 rel:%s, relAcl:%s, col:%s, colAcl:%s\n", c.get("attribute_name"), c.get("attribute_acl"), c.get("attribute_name"), c.get("attribute_acl"))

grant-relationship.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,14 @@ func (c *GrantRelationshipSchema) Compare(obj interface{}) int {
105105

106106
// Add prints SQL to add the column
107107
func (c *GrantRelationshipSchema) Add() {
108-
fmt.Println("--Add")
109108
role, grants := parseGrants(c.get("relationship_acl"))
110-
fmt.Printf("GRANT %s ON %s TO %s;\n", strings.Join(grants, ", "), c.get("relationship_name"), role)
109+
fmt.Printf("GRANT %s ON %s TO %s; -- Add\n", strings.Join(grants, ", "), c.get("relationship_name"), role)
111110
}
112111

113112
// Drop prints SQL to drop the column
114113
func (c *GrantRelationshipSchema) Drop() {
115-
fmt.Println("--Drop")
116114
role, grants := parseGrants(c.get("relationship_acl"))
117-
fmt.Printf("REVOKE %s ON %s FROM %s;\n", strings.Join(grants, ", "), c.get("relationship_name"), role)
115+
fmt.Printf("REVOKE %s ON %s FROM %s; -- Drop\n", strings.Join(grants, ", "), c.get("relationship_name"), role)
118116
}
119117

120118
// Change handles the case where the relationship and column match, but the details do not
@@ -123,7 +121,6 @@ func (c *GrantRelationshipSchema) Change(obj interface{}) {
123121
if !ok {
124122
fmt.Println("-- Error!!!, change needs a GrantRelationshipSchema instance", c2)
125123
}
126-
fmt.Println("--Change")
127124

128125
role, grants1 := parseGrants(c.get("relationship_acl"))
129126
_, grants2 := parseGrants(c2.get("relationship_acl"))
@@ -137,7 +134,7 @@ func (c *GrantRelationshipSchema) Change(obj interface{}) {
137134
}
138135
}
139136
if len(grantList) > 0 {
140-
fmt.Printf("GRANT %s ON %s TO %s;\n", strings.Join(grantList, ", "), c.get("relationship_name"), role)
137+
fmt.Printf("GRANT %s ON %s TO %s; -- Change\n", strings.Join(grantList, ", "), c.get("relationship_name"), role)
141138
}
142139

143140
// Find grants in the second db that are not in the first
@@ -149,7 +146,7 @@ func (c *GrantRelationshipSchema) Change(obj interface{}) {
149146
}
150147
}
151148
if len(revokeList) > 0 {
152-
fmt.Printf("REVOKE %s ON %s FROM %s;\n", strings.Join(revokeList, ", "), c.get("relationship_name"), role)
149+
fmt.Printf("REVOKE %s ON %s FROM %s; -- Change\n", strings.Join(revokeList, ", "), c.get("relationship_name"), role)
153150
}
154151

155152
// fmt.Printf("--1 rel:%s, relAcl:%s, col:%s, colAcl:%s\n", c.get("relationship_name"), c.get("relationship_acl"), c.get("column_name"), c.get("column_acl"))

grant_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,28 @@ func Test_parseAcls(t *testing.T) {
2727

2828
// Note that these must be sorted for this to work
2929
var relationship1 = []map[string]string{
30-
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "relationship_acl": "c42=rwa/postgres" },
31-
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "relationship_acl": "o42=xdwra/postgres" },
32-
{"schema": "public", "type": "TABLE", "relationship_name": "table2", "relationship_acl": "c42=rwa/postgres" },
30+
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "relationship_acl": "c42=rwa/postgres"},
31+
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "relationship_acl": "o42=xdwra/postgres"},
32+
{"schema": "public", "type": "TABLE", "relationship_name": "table2", "relationship_acl": "c42=rwa/postgres"},
3333
}
3434

3535
// Note that these must be sorted for this to work
3636
var relationship2 = []map[string]string{
37-
{"schema": "public", "relationship_name": "table1", "type": "TABLE", "relationship_acl": "c42=r/postgres" },
37+
{"schema": "public", "relationship_name": "table1", "type": "TABLE", "relationship_acl": "c42=r/postgres"},
3838
{"schema": "public", "relationship_name": "table2", "type": "TABLE", "relationship_acl": "c42=rwad/postgres"},
3939
}
4040

4141
// Note that these must be sorted for this to work
4242
var attribute1 = []map[string]string{
43-
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "attribute_name": "column1", "attribute_acl": "c42ro=r/postgres" },
44-
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "attribute_name": "column1", "attribute_acl": "o42ro=rwa/postgres" },
45-
{"schema": "public", "type": "TABLE", "relationship_name": "table2", "attribute_name": "column2", "attribute_acl": "c42ro=r/postgres" },
43+
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "attribute_name": "column1", "attribute_acl": "c42ro=r/postgres"},
44+
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "attribute_name": "column1", "attribute_acl": "o42ro=rwa/postgres"},
45+
{"schema": "public", "type": "TABLE", "relationship_name": "table2", "attribute_name": "column2", "attribute_acl": "c42ro=r/postgres"},
4646
}
4747

4848
// Note that these must be sorted for this to work
4949
var attribute2 = []map[string]string{
50-
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "attribute_name": "column1", "attribute_acl": "c42ro=r/postgres" },
51-
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "attribute_name": "column1", "attribute_acl": "o42ro=r/postgres" },
50+
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "attribute_name": "column1", "attribute_acl": "c42ro=r/postgres"},
51+
{"schema": "public", "type": "TABLE", "relationship_name": "table1", "attribute_name": "column1", "attribute_acl": "o42ro=r/postgres"},
5252
}
5353

5454
func Test_diffGrants(t *testing.T) {

pgdiff.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func main() {
4242
// Remaining args:
4343
args = flag.Args()
4444
if len(args) == 0 {
45-
fmt.Println("The required first argument is SchemaType: ROLE, SEQUENCE, TABLE, COLUMN, INDEX, FOREIGN_KEY, OWNER, GRANT_RELATIONSHIPS, GRANT_ATTRIBUTES")
45+
fmt.Println("The required first argument is SchemaType: ROLE, SEQUENCE, TABLE, COLUMN, INDEX, FOREIGN_KEY, OWNER, GRANT_RELATIONSHIP, GRANT_ATTRIBUTE")
4646
os.Exit(1)
4747
}
4848
schemaType = strings.ToUpper(args[0])
@@ -80,9 +80,9 @@ func main() {
8080
compareForeignKeys(conn1, conn2)
8181
} else if schemaType == "OWNER" {
8282
compareOwners(conn1, conn2)
83-
} else if schemaType == "GRANT_RELATIONSHIPS" {
83+
} else if schemaType == "GRANT_RELATIONSHIP" {
8484
compareGrantRelationships(conn1, conn2)
85-
} else if schemaType == "GRANT_ATTRIBUTES" {
85+
} else if schemaType == "GRANT_ATTRIBUTE" {
8686
compareGrantAttributes(conn1, conn2)
8787
} else {
8888
fmt.Println("Not yet handled:", schemaType)

pgdiff.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function rundiff() {
3535
#rundiff COLUMN
3636
#rundiff INDEX
3737
#rundiff FOREIGN_KEY
38-
#rundiff GRANT
39-
rundiff OWNER
38+
#rundiff OWNER
39+
rundiff GRANT_RELATIONSHIP
40+
rundiff GRANT_ATTRIBUTE
4041

0 commit comments

Comments
 (0)