Fix inserting new repeated refs into db failing #20

This commit is contained in:
2023-02-24 22:28:50 -07:00
parent 62b4e8f17e
commit 77a8d0840a
+12 -16
View File
@@ -6,7 +6,6 @@ import (
"regexp"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
)
func (db *Database) GetPipelines() ([]Pipeline, error) {
@@ -301,11 +300,11 @@ func (db *Database) UpdateRunResult(r Run) error {
query := `
UPDATE runs
SET in_progress=$1, result=$2, stdout=$3, stderr=$4
WHERE id=$3;`
WHERE id=$5;`
// TODO: does r.Result need a pointer derefrence?
_, err := db.Conn.Exec(context.Background(),
query, r.InProgress, r.Result, r.Stdout, r.Stderr)
query, r.InProgress, r.Result, r.Stdout, r.Stderr, r.Id)
return err
}
@@ -379,21 +378,18 @@ WHERE pipeline_id=$1;`
func (db *Database) UpdatePipelineRefs(pipelineId uuid.UUID, refsMap map[string]string) error {
refsSlice := make([][]interface{}, 0)
for name, ref := range refsMap {
refsSlice = append(refsSlice, []interface{}{name, pipelineId, ref})
}
query := `
INSERT INTO pipeline_refs(name, pipeline_id, hash)
VALUES($1, $2, $3)
ON CONFLICT (name)
DO
UPDATE SET hash=$3;`
copyCount, err := db.Conn.CopyFrom(
context.Background(),
pgx.Identifier{"pipeline_refs"},
[]string{"name", "pipeline_id", "hash"},
pgx.CopyFromRows(refsSlice),
)
if err != nil {
return fmt.Errorf("could not insert updated pipeline refs: %w", err)
for name, hash := range refsMap {
_, err := db.Conn.Exec(context.Background(), query, name, pipelineId, hash)
return err
}
log.Debugf("copyCount: %v", copyCount)
return nil
}