Skip to content

Commit d749235

Browse files
author
Piet Schrijver
committed
Merge branch 'master' into feature/azure-identity-role
2 parents b486bfa + f46ec22 commit d749235

File tree

5 files changed

+22
-27
lines changed

5 files changed

+22
-27
lines changed

.github/workflows/golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Golangci-Lint
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
pull_request:
88
jobs:
99
lint:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: test
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
pull_request:
88

99
jobs:

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
run:
2+
timeout: 5m
3+
14
issues:
25
exclude-rules:
36
- linters:

postgresql/resource_postgresql_default_privileges.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func resourcePostgreSQLDefaultPrivilegesRead(db *DBConnection, d *schema.Resourc
8787
)
8888
}
8989

90-
exists, err := checkRoleDBSchemaExists(db.client, d)
90+
exists, err := checkRoleDBSchemaExists(db, d)
9191
if err != nil {
9292
return err
9393
}

postgresql/resource_postgresql_grant.go

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func resourcePostgreSQLGrantRead(db *DBConnection, d *schema.ResourceData) error
109109
return fmt.Errorf("feature is not supported: %v", err)
110110
}
111111

112-
exists, err := checkRoleDBSchemaExists(db.client, d)
112+
exists, err := checkRoleDBSchemaExists(db, d)
113113
if err != nil {
114114
return err
115115
}
@@ -699,8 +699,19 @@ func revokeRolePrivileges(txn *sql.Tx, d *schema.ResourceData) error {
699699
return nil
700700
}
701701

702-
func checkRoleDBSchemaExists(client *Client, d *schema.ResourceData) (bool, error) {
703-
txn, err := startTransaction(client, "")
702+
func checkRoleDBSchemaExists(db *DBConnection, d *schema.ResourceData) (bool, error) {
703+
// Check the database exists
704+
database := d.Get("database").(string)
705+
exists, err := dbExists(db, database)
706+
if err != nil {
707+
return false, err
708+
}
709+
if !exists {
710+
log.Printf("[DEBUG] database %s does not exists", database)
711+
return false, nil
712+
}
713+
714+
txn, err := startTransaction(db.client, database)
704715
if err != nil {
705716
return false, err
706717
}
@@ -719,29 +730,10 @@ func checkRoleDBSchemaExists(client *Client, d *schema.ResourceData) (bool, erro
719730
}
720731
}
721732

722-
// Check the database exists
723-
database := d.Get("database").(string)
724-
exists, err := dbExists(txn, database)
725-
if err != nil {
726-
return false, err
727-
}
728-
if !exists {
729-
log.Printf("[DEBUG] database %s does not exists", database)
730-
return false, nil
731-
}
732-
733+
// Check the schema exists (the SQL connection needs to be on the right database)
733734
pgSchema := d.Get("schema").(string)
734-
735735
if !sliceContainsStr([]string{"database", "foreign_data_wrapper", "foreign_server"}, d.Get("object_type").(string)) && pgSchema != "" {
736-
// Connect on this database to check if schema exists
737-
dbTxn, err := startTransaction(client, database)
738-
if err != nil {
739-
return false, err
740-
}
741-
defer deferredRollback(dbTxn)
742-
743-
// Check the schema exists (the SQL connection needs to be on the right database)
744-
exists, err = schemaExists(dbTxn, pgSchema)
736+
exists, err = schemaExists(txn, pgSchema)
745737
if err != nil {
746738
return false, err
747739
}

0 commit comments

Comments
 (0)