Skip to content

Commit 6850ed9

Browse files
fix: Unordered tables in postgresql_publication (#219)
* order publication tables * Add missing space in the query * Convert publication tables from TypeList to TypeSet * Remove redundant error handling
1 parent 5e17463 commit 6850ed9

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

postgresql/resource_postgresql_publication.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func resourcePostgreSQLPublication() *schema.Resource {
5656
ValidateFunc: validation.StringIsNotEmpty,
5757
},
5858
pubTablesAttr: {
59-
Type: schema.TypeList,
59+
Type: schema.TypeSet,
6060
Optional: true,
6161
Computed: true,
6262
ForceNew: false,
@@ -174,8 +174,8 @@ func setPubTables(txn *sql.Tx, d *schema.ResourceData) error {
174174
pubName := d.Get(pubNameAttr).(string)
175175

176176
oraw, nraw := d.GetChange(pubTablesAttr)
177-
oldList := oraw.([]interface{})
178-
newList := nraw.([]interface{})
177+
oldList := oraw.(*schema.Set).List()
178+
newList := nraw.(*schema.Set).List()
179179
if elem, ok := isUniqueArr(newList); !ok {
180180
return fmt.Errorf("'%s' is duplicated for attribute `%s`", elem.(string), pubTablesAttr)
181181
}
@@ -372,13 +372,10 @@ func resourcePostgreSQLPublicationReadImpl(db *DBConnection, d *schema.ResourceD
372372
}
373373
tables = append(tables, table)
374374
}
375-
376-
switch {
377-
case err == sql.ErrNoRows:
378-
log.Printf("[WARN] No PostgreSQL tables found for Publication %s", PublicationName)
379-
case err != nil:
380-
return fmt.Errorf("Error reading Publication tables: %w", err)
375+
if err := rows.Err(); err != nil {
376+
return fmt.Errorf("Got rows.Err: %w", err)
381377
}
378+
382379
if pubinsert {
383380
publishParams = append(publishParams, "insert")
384381
}
@@ -449,7 +446,7 @@ func getDatabaseForPublication(d *schema.ResourceData, databaseName string) stri
449446

450447
func getTablesForPublication(d *schema.ResourceData) (string, error) {
451448
var tablesString string
452-
tables, ok := d.GetOk(pubTablesAttr)
449+
setTables, ok := d.GetOk(pubTablesAttr)
453450
isAllTables, isAllOk := d.GetOk(pubAllTablesAttr)
454451

455452
if isAllOk {
@@ -458,11 +455,12 @@ func getTablesForPublication(d *schema.ResourceData) (string, error) {
458455
}
459456
}
460457
if ok {
458+
tables := setTables.(*schema.Set).List()
461459
var tlist []string
462-
if elem, ok := isUniqueArr(tables.([]interface{})); !ok {
460+
if elem, ok := isUniqueArr(tables); !ok {
463461
return tablesString, fmt.Errorf("'%s' is duplicated for attribute `%s`", elem.(string), pubTablesAttr)
464462
}
465-
for _, t := range tables.([]interface{}) {
463+
for _, t := range tables {
466464
tlist = append(tlist, t.(string))
467465
}
468466
tablesString = fmt.Sprintf("FOR TABLE %s", strings.Join(tlist, ", "))

0 commit comments

Comments
 (0)