diff --git a/internal/testing/backend/artifact_test.go b/internal/testing/backend/artifact_test.go index d819838a54..80ed14d5a1 100644 --- a/internal/testing/backend/artifact_test.go +++ b/internal/testing/backend/artifact_test.go @@ -66,6 +66,21 @@ func TestArtifacts(t *testing.T) { Digest: "7a8f47318e4676dacb0142afa0b83029cd7befd9", }}, wantErr: false, + }, { + name: "sha-1", + artifactInput: &model.ArtifactInputSpec{ + Algorithm: "SHA-1", + Digest: "7A8F47318E4676DACB0142AFA0B83029CD7BEFD9", + }, + artifactSpec: &model.ArtifactSpec{ + Algorithm: ptrfrom.String("SHA-1"), + Digest: ptrfrom.String("7A8F47318E4676DACB0142AFA0B83029CD7BEFD9"), + }, + want: []*model.Artifact{{ + Algorithm: "sha-1", + Digest: "7a8f47318e4676dacb0142afa0b83029cd7befd9", + }}, + wantErr: false, }, { name: "sha512", artifactInput: &model.ArtifactInputSpec{ diff --git a/pkg/assembler/backends/arangodb/backend.go b/pkg/assembler/backends/arangodb/backend.go index 559730f94a..43e55f447b 100644 --- a/pkg/assembler/backends/arangodb/backend.go +++ b/pkg/assembler/backends/arangodb/backend.go @@ -64,7 +64,7 @@ func init() { func initIndex(name string, fields []string, unique bool) index { return index{ - name: name, + name: name, fields: fields, unique: unique, } @@ -514,7 +514,6 @@ func getCollectionIndexMap() map[string][]index { collectionIndexMap := make(map[string][]index) collectionIndexMap[artifactsStr] = []index{ - initIndex("byDigest", []string{"digest"}, true), initIndex("byArtAndDigest", []string{"algorithm", "digest"}, true), } diff --git a/pkg/assembler/backends/ent/backend/artifact.go b/pkg/assembler/backends/ent/backend/artifact.go index 5334cfd34e..021e70d0f2 100644 --- a/pkg/assembler/backends/ent/backend/artifact.go +++ b/pkg/assembler/backends/ent/backend/artifact.go @@ -96,6 +96,8 @@ func upsertBulkArtifact(ctx context.Context, tx *ent.Tx, artInputs []*model.IDor batches := chunk(artInputs, MaxBatchSize) ids := make([]string, 0) + conflictColumns := []string{artifact.FieldAlgorithm, artifact.FieldDigest} + for _, artifacts := range batches { creates := make([]*ent.ArtifactCreate, len(artifacts)) for i, art := range artifacts { @@ -108,7 +110,7 @@ func upsertBulkArtifact(ctx context.Context, tx *ent.Tx, artInputs []*model.IDor err := tx.Artifact.CreateBulk(creates...). OnConflict( - sql.ConflictColumns(artifact.FieldDigest), + sql.ConflictColumns(conflictColumns...), ). DoNothing(). Exec(ctx) @@ -128,11 +130,14 @@ func generateArtifactCreate(tx *ent.Tx, artifactID *uuid.UUID, art *model.IDorAr } func upsertArtifact(ctx context.Context, tx *ent.Tx, art *model.IDorArtifactInput) (*string, error) { + + conflictColumns := []string{artifact.FieldAlgorithm, artifact.FieldDigest} + artifactID := generateUUIDKey([]byte(helpers.GetKey[*model.ArtifactInputSpec, string](art.ArtifactInput, helpers.ArtifactServerKey))) insert := generateArtifactCreate(tx, &artifactID, art) err := insert. OnConflict( - sql.ConflictColumns(artifact.FieldDigest), + sql.ConflictColumns(conflictColumns...), ). DoNothing(). Exec(ctx) diff --git a/pkg/assembler/backends/ent/migrate/schema.go b/pkg/assembler/backends/ent/migrate/schema.go index 3402418b14..a831acde9d 100644 --- a/pkg/assembler/backends/ent/migrate/schema.go +++ b/pkg/assembler/backends/ent/migrate/schema.go @@ -22,14 +22,9 @@ var ( PrimaryKey: []*schema.Column{ArtifactsColumns[0]}, Indexes: []*schema.Index{ { - Name: "artifact_algorithm", - Unique: false, - Columns: []*schema.Column{ArtifactsColumns[1]}, - }, - { - Name: "artifact_digest", + Name: "artifact_algorithm_digest", Unique: true, - Columns: []*schema.Column{ArtifactsColumns[2]}, + Columns: []*schema.Column{ArtifactsColumns[1], ArtifactsColumns[2]}, }, }, } diff --git a/pkg/assembler/backends/ent/schema/artifact.go b/pkg/assembler/backends/ent/schema/artifact.go index 70b04461ce..a56803830f 100644 --- a/pkg/assembler/backends/ent/schema/artifact.go +++ b/pkg/assembler/backends/ent/schema/artifact.go @@ -72,7 +72,6 @@ func (Artifact) Edges() []ent.Edge { // to query all artifacts using a specific algorithm. func (Artifact) Indexes() []ent.Index { return []ent.Index{ - index.Fields("algorithm"), - index.Fields("digest").Unique(), + index.Fields("algorithm", "digest").Unique(), } }