Skip to content
Merged
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
25 changes: 19 additions & 6 deletions postgresql/resource_cockroachdb_changefeed.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package postgresql

import (
"database/sql"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"regexp"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

const (
Expand Down Expand Up @@ -108,8 +110,10 @@ func resourceCockroachDBChangefeedCreate(db *DBConnection, d *schema.ResourceDat
if err = txn.QueryRow(sqlChangefeed).Scan(&jobID); err != nil {
return fmt.Errorf("error creating changefeed: %w", err)
}
if err = txn.Commit(); err != nil {
return fmt.Errorf("could not commit transaction: %w", err)
if db.dbType != dbTypeCockroachdb {
if err = txn.Commit(); err != nil {
return fmt.Errorf("could not commit transaction: %w", err)
}
}

d.SetId(jobID)
Expand All @@ -122,8 +126,14 @@ func resourceCockroachDBChangefeedCreate(db *DBConnection, d *schema.ResourceDat
}

func resourceCockroachDBChangefeedRead(db *DBConnection, d *schema.ResourceData) error {
exists, err := resourceCockroachDBChangefeedExists(db, d)
if err != nil {
return err
}
if !exists {
return resourceCockroachDBChangefeedCreate(db, d)
}
return resourceCockroachDBChangefeedReadImpl(db, d)
//return nil
}

func resourceCockroachDBChangefeedReadImpl(db *DBConnection, d *schema.ResourceData) error {
Expand Down Expand Up @@ -260,8 +270,11 @@ func resourceCockroachDBChangefeedUpdate(db *DBConnection, d *schema.ResourceDat
// helper functions
func jobExists(db QueryAble, jobID string) (bool, error) {
var jobIDExists string
err := db.QueryRow(fmt.Sprintf("SELECT job_id FROM [SHOW changefeed JOB %s];", jobID)).Scan(&jobIDExists)
err := db.QueryRow(fmt.Sprintf("SELECT job_id FROM [SHOW changefeed JOB %s] where status='running';", jobID)).Scan(&jobIDExists)
if err != nil {
if err == sql.ErrNoRows {
return false, nil
}
return false, err
}
return jobIDExists == jobID, nil
Expand Down
Loading