Skip to content

Commit f7a64cd

Browse files
committed
datastore: add package_db to package table
rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED
1 parent 9ca2436 commit f7a64cd

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

datastore/postgres/indexpackage.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ var (
4848
// particular scanner. See the LayerScanned method for more details.
4949
func (s *IndexerStore) IndexPackages(ctx context.Context, pkgs []*claircore.Package, layer *claircore.Layer, scnr indexer.VersionedScanner) error {
5050
const (
51-
insert = `
52-
INSERT INTO package (name, kind, version, norm_kind, norm_version, module, arch)
53-
VALUES ($1, $2, $3, $4, $5::int[], $6, $7)
54-
ON CONFLICT (name, kind, version, module, arch) DO NOTHING;
51+
insert = `
52+
INSERT INTO package (name, kind, version, norm_kind, norm_version, module, arch, package_db)
53+
VALUES ($1, $2, $3, $4, $5::int[], $6, $7, $8)
54+
ON CONFLICT (name, kind, version, module, arch, package_db) DO NOTHING;
5555
`
5656

5757
insertWith = `
@@ -64,27 +64,27 @@ func (s *IndexerStore) IndexPackages(ctx context.Context, pkgs []*claircore.Pack
6464
AND module = $4
6565
AND arch = $5
6666
),
67-
binary_package AS (
68-
SELECT id AS package_id
69-
FROM package
70-
WHERE name = $6
71-
AND kind = $7
72-
AND version = $8
73-
AND module = $9
74-
AND arch = $10
75-
),
76-
scanner AS (
77-
SELECT id AS scanner_id
78-
FROM scanner
79-
WHERE name = $11
80-
AND version = $12
81-
AND kind = $13
82-
),
83-
layer AS (
84-
SELECT id AS layer_id
85-
FROM layer
86-
WHERE layer.hash = $14
87-
)
67+
binary_package AS (
68+
SELECT id AS package_id
69+
FROM package
70+
WHERE name = $6
71+
AND kind = $7
72+
AND version = $8
73+
AND module = $9
74+
AND arch = $10
75+
),
76+
scanner AS (
77+
SELECT id AS scanner_id
78+
FROM scanner
79+
WHERE name = $11
80+
AND version = $12
81+
AND kind = $13
82+
),
83+
layer AS (
84+
SELECT id AS layer_id
85+
FROM layer
86+
WHERE layer.hash = $14
87+
)
8888
INSERT
8989
INTO package_scanartifact (layer_id, package_db, repository_hint, filepath, package_id, source_id, scanner_id)
9090
VALUES ((SELECT layer_id FROM layer),
@@ -207,7 +207,7 @@ func queueInsert(ctx context.Context, b *microbatch.Insert, stmt string, pkg *cl
207207
vNorm = pkg.NormalizedVersion.V[:]
208208
}
209209
err := b.Queue(ctx, stmt,
210-
pkg.Name, pkg.Kind, pkg.Version, vKind, vNorm, pkg.Module, pkg.Arch,
210+
pkg.Name, pkg.Kind, pkg.Version, vKind, vNorm, pkg.Module, pkg.Arch, pkg.PackageDB,
211211
)
212212
if err != nil {
213213
return fmt.Errorf("failed to queue insert for package %q: %w", pkg.Name, err)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- The package table only save one copy for each unique name+version of a package (and a few more fields).
2+
-- It is possible an image has several packages with the same name+version (and the other fields)
3+
-- in different locations. Without this migration, the IndexReport only tracks one of those packages
4+
-- instead of a package for each unique location.
5+
ALTER TABLE IF EXISTS package ADD COLUMN package_db text;
6+
DROP INDEX IF EXISTS package_unique_idx;
7+
CREATE UNIQUE INDEX IF NOT EXISTS package_unique_idx ON package (name, version, kind, module, arch, package_db);

datastore/postgres/migrations/migrations.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ var IndexerMigrations = []migrate.Migration{
6565
ID: 9,
6666
Up: runFile("indexer/09-delete-scannerlist.sql"),
6767
},
68+
{
69+
ID: 10,
70+
Up: runFile("indexer/10-package-db.sql"),
71+
},
6872
}
6973

7074
var MatcherMigrations = []migrate.Migration{

0 commit comments

Comments
 (0)