-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathazure.go
More file actions
49 lines (40 loc) · 1.01 KB
/
azure.go
File metadata and controls
49 lines (40 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package postgres
import (
"github.com/lib/pq"
)
type AzureType string
type azurepg struct {
pg
}
func newAzurePG(postgres *pg) PG {
return &azurepg{
pg: *postgres,
}
}
func (azpg *azurepg) CreateUserRole(role, password string) (string, error) {
returnedRole, err := azpg.pg.CreateUserRole(role, password)
if err != nil {
return "", err
}
return returnedRole, nil
}
func (azpg *azurepg) CreateDB(dbname, role string) error {
// This step is necessary before we can set the specified role as the database owner
err := azpg.GrantRole(role, azpg.user)
if err != nil {
return err
}
return azpg.pg.CreateDB(dbname, role)
}
func (azpg *azurepg) DropRole(role, newOwner, database string) error {
// Grant the role to the user first
err := azpg.GrantRole(role, azpg.user)
if err != nil && err.(*pq.Error).Code != "0LP01" {
if err.(*pq.Error).Code == "42704" {
return nil
}
return err
}
// Delegate to parent implementation to perform the actual drop
return azpg.pg.DropRole(role, newOwner, database)
}