Fix inserting new repeated refs into db failing #20
This commit is contained in:
+12
-16
@@ -6,7 +6,6 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (db *Database) GetPipelines() ([]Pipeline, error) {
|
func (db *Database) GetPipelines() ([]Pipeline, error) {
|
||||||
@@ -301,11 +300,11 @@ func (db *Database) UpdateRunResult(r Run) error {
|
|||||||
query := `
|
query := `
|
||||||
UPDATE runs
|
UPDATE runs
|
||||||
SET in_progress=$1, result=$2, stdout=$3, stderr=$4
|
SET in_progress=$1, result=$2, stdout=$3, stderr=$4
|
||||||
WHERE id=$3;`
|
WHERE id=$5;`
|
||||||
|
|
||||||
// TODO: does r.Result need a pointer derefrence?
|
// TODO: does r.Result need a pointer derefrence?
|
||||||
_, err := db.Conn.Exec(context.Background(),
|
_, 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
|
return err
|
||||||
}
|
}
|
||||||
@@ -379,21 +378,18 @@ WHERE pipeline_id=$1;`
|
|||||||
|
|
||||||
func (db *Database) UpdatePipelineRefs(pipelineId uuid.UUID, refsMap map[string]string) error {
|
func (db *Database) UpdatePipelineRefs(pipelineId uuid.UUID, refsMap map[string]string) error {
|
||||||
|
|
||||||
refsSlice := make([][]interface{}, 0)
|
query := `
|
||||||
for name, ref := range refsMap {
|
INSERT INTO pipeline_refs(name, pipeline_id, hash)
|
||||||
refsSlice = append(refsSlice, []interface{}{name, pipelineId, ref})
|
VALUES($1, $2, $3)
|
||||||
}
|
ON CONFLICT (name)
|
||||||
|
DO
|
||||||
|
UPDATE SET hash=$3;`
|
||||||
|
|
||||||
copyCount, err := db.Conn.CopyFrom(
|
for name, hash := range refsMap {
|
||||||
context.Background(),
|
_, err := db.Conn.Exec(context.Background(), query, name, pipelineId, hash)
|
||||||
pgx.Identifier{"pipeline_refs"},
|
|
||||||
[]string{"name", "pipeline_id", "hash"},
|
return err
|
||||||
pgx.CopyFromRows(refsSlice),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could not insert updated pipeline refs: %w", err)
|
|
||||||
}
|
}
|
||||||
log.Debugf("copyCount: %v", copyCount)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user