Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions postgresql/resource_postgresql_publication.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func setPubOwner(txn *sql.Tx, d *schema.ResourceData) error {
n := nraw.(string)
pubName := d.Get(pubNameAttr).(string)

sql := fmt.Sprintf("ALTER PUBLICATION %s OWNER TO %s", pubName, n)
sql := fmt.Sprintf("ALTER PUBLICATION %s OWNER TO %s", pq.QuoteIdentifier(pubName), pq.QuoteIdentifier(n))
if _, err := txn.Exec(sql); err != nil {
return fmt.Errorf("error updating publication owner: %w", err)
}
Expand All @@ -183,12 +183,12 @@ func setPubTables(txn *sql.Tx, d *schema.ResourceData) error {
added := arrayDifference(newList, oldList)

for _, p := range added {
query := fmt.Sprintf("ALTER PUBLICATION %s ADD TABLE %s", pubName, quoteTableName(p.(string)))
query := fmt.Sprintf("ALTER PUBLICATION %s ADD TABLE %s", pq.QuoteIdentifier(pubName), quoteTableName(p.(string)))
queries = append(queries, query)
}

for _, p := range dropped {
query := fmt.Sprintf("ALTER PUBLICATION %s DROP TABLE %s", pubName, quoteTableName(p.(string)))
query := fmt.Sprintf("ALTER PUBLICATION %s DROP TABLE %s", pq.QuoteIdentifier(pubName), quoteTableName(p.(string)))
queries = append(queries, query)
}

Expand All @@ -208,7 +208,7 @@ func setPubParams(txn *sql.Tx, d *schema.ResourceData, pubViaRootEnabled bool) e
return fmt.Errorf("error getting publication parameters: %w", err)
}
if publicationParametersString != "" {
sql := fmt.Sprintf(paramAlterTemplate, pubName, publicationParametersString)
sql := fmt.Sprintf(paramAlterTemplate, pq.QuoteIdentifier(pubName), publicationParametersString)
if _, err := txn.Exec(sql); err != nil {
return fmt.Errorf("error updating publication parameters: %w", err)
}
Expand Down Expand Up @@ -240,7 +240,7 @@ func resourcePostgreSQLPublicationCreate(db *DBConnection, d *schema.ResourceDat
}
defer deferredRollback(txn)

sql := fmt.Sprintf("CREATE PUBLICATION %s %s %s", name, tables, publicationParameters)
sql := fmt.Sprintf("CREATE PUBLICATION %s %s %s", pq.QuoteIdentifier(name), tables, publicationParameters)

if _, err := txn.Exec(sql); err != nil {
return fmt.Errorf("error creating Publication: %w", err)
Expand Down
16 changes: 8 additions & 8 deletions postgresql/resource_postgresql_publication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func TestAccPostgresqlPublication_UpdateOwner(t *testing.T) {

testAccPostgresqlPublicationUpdateOwnerConfig := fmt.Sprintf(`
resource "postgresql_role" "test_owner_2" {
name = "%s_2"
name = "%s-2"
login = true
}
resource "postgresql_publication" "test" {
Expand Down Expand Up @@ -403,11 +403,11 @@ func TestAccPostgresqlPublication_UpdateOwner(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckPostgresqlPublicationExists("postgresql_publication.test"),
resource.TestCheckResourceAttr(
"postgresql_role.test_owner_2", "name", fmt.Sprintf("%s_2", testOwner)),
"postgresql_role.test_owner_2", "name", fmt.Sprintf("%s-2", testOwner)),
resource.TestCheckResourceAttr(
"postgresql_publication.test", "name", "publication"),
resource.TestCheckResourceAttr(
"postgresql_publication.test", "owner", fmt.Sprintf("%s_2", testOwner)),
"postgresql_publication.test", "owner", fmt.Sprintf("%s-2", testOwner)),
resource.TestCheckResourceAttr(
"postgresql_publication.test", "database", dbName),
),
Expand All @@ -426,14 +426,14 @@ func TestAccPostgresqlPublication_UpdateName(t *testing.T) {

testAccPostgresqlPublicationBaseConfig := fmt.Sprintf(`
resource "postgresql_publication" "test" {
name = "%s_publication_1"
name = "%s-publication-1"
database = "%s"
}
`, dbName, dbName)

testAccPostgresqlPublicationUpdateNameConfig := fmt.Sprintf(`
resource "postgresql_publication" "test" {
name = "%s_publication_2"
name = "%s-publication-2"
database = "%s"
}
`, dbName, dbName)
Expand All @@ -453,7 +453,7 @@ func TestAccPostgresqlPublication_UpdateName(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckPostgresqlPublicationExists("postgresql_publication.test"),
resource.TestCheckResourceAttr(
"postgresql_publication.test", "name", fmt.Sprintf("%s_publication_1", dbName)),
"postgresql_publication.test", "name", fmt.Sprintf("%s-publication-1", dbName)),
resource.TestCheckResourceAttr(
"postgresql_publication.test", "database", dbName),
),
Expand All @@ -463,7 +463,7 @@ func TestAccPostgresqlPublication_UpdateName(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckPostgresqlPublicationExists("postgresql_publication.test"),
resource.TestCheckResourceAttr(
"postgresql_publication.test", "name", fmt.Sprintf("%s_publication_2", dbName)),
"postgresql_publication.test", "name", fmt.Sprintf("%s-publication-2", dbName)),
resource.TestCheckResourceAttr(
"postgresql_publication.test", "database", dbName),
),
Expand All @@ -473,7 +473,7 @@ func TestAccPostgresqlPublication_UpdateName(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckPostgresqlPublicationExists("postgresql_publication.test"),
resource.TestCheckResourceAttr(
"postgresql_publication.test", "name", fmt.Sprintf("%s_publication_1", dbName)),
"postgresql_publication.test", "name", fmt.Sprintf("%s-publication-1", dbName)),
resource.TestCheckResourceAttr(
"postgresql_publication.test", "database", dbName),
),
Expand Down