|
1 | 1 | --- Layer |
2 | 2 | --- an identity table consisting of a content addressable layer hash |
3 | | -CREATE TABLE IF NOT EXISTS layer ( |
4 | | - hash text PRIMARY KEY |
5 | | -); |
| 3 | +CREATE TABLE IF NOT EXISTS layer (hash text PRIMARY KEY); |
6 | 4 |
|
7 | 5 | --- Manifest |
8 | 6 | --- an identity table consisting of a content addressable manifest hash |
9 | | -CREATE TABLE IF NOT EXISTS manifest ( |
10 | | - hash text PRIMARY KEY |
11 | | -); |
| 7 | +CREATE TABLE IF NOT EXISTS manifest (hash text PRIMARY KEY); |
12 | 8 |
|
13 | 9 | --- ManifestLayer |
14 | 10 | --- a many to many link table identifying the layers which comprise a manifest |
15 | 11 | --- and the layer's ordering within a manifest |
16 | 12 | CREATE TABLE IF NOT EXISTS manifest_layer ( |
17 | | - manifest_hash text REFERENCES manifest(hash), |
18 | | - layer_hash text REFERENCES layer(hash), |
19 | | - i bigint, |
20 | | - PRIMARY KEY(manifest_hash, layer_hash, i) |
| 13 | + manifest_hash text REFERENCES manifest (hash), |
| 14 | + layer_hash text REFERENCES layer (hash), |
| 15 | + i bigint, |
| 16 | + PRIMARY KEY (manifest_hash, layer_hash, i) |
21 | 17 | ); |
22 | 18 |
|
23 | 19 | --- Scanner |
24 | 20 | --- a unique versioned scanner which is responsible |
25 | 21 | --- for finding packages and distributions in a layer |
26 | 22 | CREATE TABLE IF NOT EXISTS scanner ( |
27 | | - id BIGSERIAL PRIMARY KEY, |
28 | | - name text NOT NULL, |
29 | | - version text NOT NULL, |
30 | | - kind text NOT NULL |
| 23 | + id BIGSERIAL PRIMARY KEY, |
| 24 | + name text NOT NULL, |
| 25 | + version text NOT NULL, |
| 26 | + kind text NOT NULL |
31 | 27 | ); |
| 28 | + |
32 | 29 | CREATE UNIQUE INDEX IF NOT EXISTS scanner_unique_idx ON scanner (name, kind, version); |
33 | 30 |
|
34 | 31 | --- ScannedManifest |
35 | 32 | --- a relation to identify if a manifest was successfully scanned by a particular |
36 | 33 | --- scanner |
37 | 34 | CREATE TABLE IF NOT EXISTS scanned_manifest ( |
38 | | - manifest_hash text REFERENCES manifest(hash), |
39 | | - scanner_id bigint REFERENCES scanner(id), |
40 | | - PRIMARY KEY(manifest_hash, scanner_id) |
| 35 | + manifest_hash text REFERENCES manifest (hash), |
| 36 | + scanner_id bigint REFERENCES scanner (id), |
| 37 | + PRIMARY KEY (manifest_hash, scanner_id) |
41 | 38 | ); |
42 | 39 |
|
43 | 40 | --- ScannedLayer |
44 | 41 | --- a relation to identify if a layer was successfully scanned by a particular scanner |
45 | 42 | CREATE TABLE IF NOT EXISTS scanned_layer ( |
46 | | - layer_hash text REFERENCES layer(hash), |
47 | | - scanner_id bigint REFERENCES scanner(id), |
48 | | - PRIMARY KEY(layer_hash, scanner_id) |
| 43 | + layer_hash text REFERENCES layer (hash), |
| 44 | + scanner_id bigint REFERENCES scanner (id), |
| 45 | + PRIMARY KEY (layer_hash, scanner_id) |
49 | 46 | ); |
50 | 47 |
|
51 | 48 | --- ScannerList |
52 | 49 | --- a relation informing us if a manifest hash has |
53 | 50 | --- been scanned by a particular scanner |
54 | 51 | CREATE TABLE IF NOT EXISTS scannerlist ( |
55 | | - id BIGSERIAL PRIMARY KEY, |
56 | | - manifest_hash text, |
57 | | - scanner_id bigint REFERENCES scanner(id) |
| 52 | + id BIGSERIAL PRIMARY KEY, |
| 53 | + manifest_hash text, |
| 54 | + scanner_id bigint REFERENCES scanner (id) |
58 | 55 | ); |
| 56 | + |
59 | 57 | CREATE INDEX IF NOT EXISTS scannerlist_manifest_hash_idx ON scannerlist (manifest_hash); |
60 | 58 |
|
61 | 59 | --- IndexReport |
62 | 60 | --- the jsonb serialized result of a scan for a particular |
63 | 61 | --- manifest |
64 | 62 | CREATE TABLE IF NOT EXISTS indexreport ( |
65 | | - manifest_hash text PRIMARY KEY REFERENCES manifest(hash), |
66 | | - state text, |
67 | | - scan_result jsonb |
| 63 | + manifest_hash text PRIMARY KEY REFERENCES manifest (hash), |
| 64 | + state text, |
| 65 | + scan_result jsonb |
68 | 66 | ); |
69 | 67 |
|
70 | 68 | -- Distribution |
71 | 69 | --- a unique distribution discovered by a scanner |
72 | 70 | CREATE TABLE IF NOT EXISTS dist ( |
73 | | - id BIGSERIAL PRIMARY KEY, |
74 | | - name text NOT NULL DEFAULT '', |
75 | | - did text NOT NULL DEFAULT '', -- os-release id field |
76 | | - version text NOT NULL DEFAULT '', |
77 | | - version_code_name text NOT NULL DEFAULT '', |
78 | | - version_id text NOT NULL DEFAULT '', |
79 | | - arch text NOT NULL DEFAULT '', |
80 | | - cpe text NOT NULL DEFAULT '', |
81 | | - pretty_name text NOT NULL DEFAULT '' |
| 71 | + id BIGSERIAL PRIMARY KEY, |
| 72 | + name text NOT NULL DEFAULT '', |
| 73 | + did text NOT NULL DEFAULT '', -- os-release id field |
| 74 | + version text NOT NULL DEFAULT '', |
| 75 | + version_code_name text NOT NULL DEFAULT '', |
| 76 | + version_id text NOT NULL DEFAULT '', |
| 77 | + arch text NOT NULL DEFAULT '', |
| 78 | + cpe text NOT NULL DEFAULT '', |
| 79 | + pretty_name text NOT NULL DEFAULT '' |
| 80 | +); |
| 81 | + |
| 82 | +CREATE UNIQUE INDEX IF NOT EXISTS dist_unique_idx ON dist ( |
| 83 | + name, |
| 84 | + did, |
| 85 | + version, |
| 86 | + version_code_name, |
| 87 | + version_id, |
| 88 | + arch, |
| 89 | + cpe, |
| 90 | + pretty_name |
82 | 91 | ); |
83 | | -CREATE UNIQUE INDEX IF NOT EXISTS dist_unique_idx ON dist (name, did, version, version_code_name, version_id, arch, cpe, pretty_name); |
84 | 92 |
|
85 | 93 | --- DistributionScanArtifact |
86 | 94 | --- A relation linking discovered distributions to a layer |
87 | 95 | CREATE TABLE IF NOT EXISTS dist_scanartifact ( |
88 | | - dist_id bigint REFERENCES dist(id), |
89 | | - scanner_id bigint REFERENCES scanner(id), |
90 | | - layer_hash text REFERENCES layer(hash), |
91 | | - PRIMARY KEY(dist_id, scanner_id, layer_hash) |
| 96 | + dist_id bigint REFERENCES dist (id), |
| 97 | + scanner_id bigint REFERENCES scanner (id), |
| 98 | + layer_hash text REFERENCES layer (hash), |
| 99 | + PRIMARY KEY (dist_id, scanner_id, layer_hash) |
92 | 100 | ); |
93 | | -CREATE INDEX IF NOT EXISTS dist_scanartifact_lookup_idx ON dist_scanartifact(layer_hash); |
| 101 | + |
| 102 | +CREATE INDEX IF NOT EXISTS dist_scanartifact_lookup_idx ON dist_scanartifact (layer_hash); |
94 | 103 |
|
95 | 104 | --- Package |
96 | 105 | --- a unique package discovered by a scanner |
97 | 106 | CREATE TABLE IF NOT EXISTS package ( |
98 | | - id BIGSERIAL PRIMARY KEY, |
99 | | - name text NOT NULL, |
100 | | - kind text NOT NULL DEFAULT '', |
101 | | - version text NOT NULL DEFAULT '', |
102 | | - norm_kind text, |
103 | | - norm_version integer[10], |
104 | | - module text NOT NULL DEFAULT '', |
105 | | - arch text NOT NULL DEFAULT '' |
| 107 | + id BIGSERIAL PRIMARY KEY, |
| 108 | + name text NOT NULL, |
| 109 | + kind text NOT NULL DEFAULT '', |
| 110 | + version text NOT NULL DEFAULT '', |
| 111 | + norm_kind text, |
| 112 | + norm_version integer[10], |
| 113 | + module text NOT NULL DEFAULT '', |
| 114 | + arch text NOT NULL DEFAULT '' |
106 | 115 | ); |
| 116 | + |
107 | 117 | CREATE UNIQUE INDEX IF NOT EXISTS package_unique_idx ON package (name, version, kind, module, arch); |
108 | 118 |
|
109 | 119 | --- PackageScanArtifact |
110 | 120 | --- A relation linking discovered packages with the |
111 | 121 | --- layer hash it was found |
112 | 122 | CREATE TABLE IF NOT EXISTS package_scanartifact ( |
113 | | - layer_hash text REFERENCES layer(hash), |
114 | | - package_id bigint REFERENCES package(id), |
115 | | - source_id bigint REFERENCES package(id), |
116 | | - scanner_id bigint REFERENCES scanner(id), |
117 | | - package_db text, |
118 | | - repository_hint text, |
119 | | - PRIMARY KEY(layer_hash, package_id, source_id, scanner_id, package_db, repository_hint) |
| 123 | + layer_hash text REFERENCES layer (hash), |
| 124 | + package_id bigint REFERENCES package (id), |
| 125 | + source_id bigint REFERENCES package (id), |
| 126 | + scanner_id bigint REFERENCES scanner (id), |
| 127 | + package_db text, |
| 128 | + repository_hint text, |
| 129 | + PRIMARY KEY ( |
| 130 | + layer_hash, |
| 131 | + package_id, |
| 132 | + source_id, |
| 133 | + scanner_id, |
| 134 | + package_db, |
| 135 | + repository_hint |
| 136 | + ) |
120 | 137 | ); |
121 | | -CREATE INDEX IF NOT EXISTS package_scanartifact_lookup_idx ON package_scanartifact(layer_hash); |
| 138 | + |
| 139 | +CREATE INDEX IF NOT EXISTS package_scanartifact_lookup_idx ON package_scanartifact (layer_hash); |
122 | 140 |
|
123 | 141 | --- Repository |
124 | 142 | --- a unique package repository discovered by a scanner |
125 | 143 | CREATE TABLE IF NOT EXISTS repo ( |
126 | | - id BIGSERIAL PRIMARY KEY, |
127 | | - name text NOT NULL, |
128 | | - key text DEFAULT '', |
129 | | - uri text DEFAULT '', |
130 | | - cpe text DEFAULT '' |
| 144 | + id BIGSERIAL PRIMARY KEY, |
| 145 | + name text NOT NULL, |
| 146 | + key text DEFAULT '', |
| 147 | + uri text DEFAULT '', |
| 148 | + cpe text DEFAULT '' |
131 | 149 | ); |
| 150 | + |
132 | 151 | CREATE UNIQUE INDEX IF NOT EXISTS repo_unique_idx ON repo (name, key, uri); |
133 | 152 |
|
134 | 153 | --- RepositoryScanArtifact |
135 | 154 | --- A relation linking discovered distributions to a layer |
136 | 155 | CREATE TABLE IF NOT EXISTS repo_scanartifact ( |
137 | | - repo_id bigint REFERENCES repo(id), |
138 | | - scanner_id bigint REFERENCES scanner(id), |
139 | | - layer_hash text REFERENCES layer(hash), |
140 | | - PRIMARY KEY(repo_id, scanner_id, layer_hash) |
| 156 | + repo_id bigint REFERENCES repo (id), |
| 157 | + scanner_id bigint REFERENCES scanner (id), |
| 158 | + layer_hash text REFERENCES layer (hash), |
| 159 | + PRIMARY KEY (repo_id, scanner_id, layer_hash) |
141 | 160 | ); |
142 | | -CREATE INDEX IF NOT EXISTS repo_scanartifact_lookup_idx ON repo_scanartifact(layer_hash); |
| 161 | + |
| 162 | +CREATE INDEX IF NOT EXISTS repo_scanartifact_lookup_idx ON repo_scanartifact (layer_hash); |
143 | 163 |
|
144 | 164 | --- ManifestIndex |
145 | 165 | --- A searchable index of a coalesced manifest's content. |
146 | 166 | --- a package id is required. |
147 | 167 | --- either a dist_id or a repo_id maybe null, but not both |
148 | | -CREATE TABLE IF NOT EXISTS manifest_index |
149 | | -( |
150 | | - id bigserial PRIMARY KEY, |
151 | | - package_id bigint NOT NULL REFERENCES package (id), |
152 | | - dist_id bigint REFERENCES dist (id), |
153 | | - repo_id bigint REFERENCES repo (id), |
154 | | - manifest_hash text REFERENCES manifest (hash) |
| 168 | +CREATE TABLE IF NOT EXISTS manifest_index ( |
| 169 | + id bigserial PRIMARY KEY, |
| 170 | + package_id bigint NOT NULL REFERENCES package (id), |
| 171 | + dist_id bigint REFERENCES dist (id), |
| 172 | + repo_id bigint REFERENCES repo (id), |
| 173 | + manifest_hash text REFERENCES manifest (hash) |
155 | 174 | ); |
| 175 | + |
156 | 176 | CREATE INDEX IF NOT EXISTS manifest_index_hash_lookup_idx ON manifest_index (manifest_hash); |
157 | | -CREATE UNIQUE INDEX manifest_index_unique ON manifest_index (package_id, COALESCE(dist_id, 0), COALESCE(repo_id, 0), manifest_hash); |
| 177 | + |
| 178 | +CREATE UNIQUE INDEX manifest_index_unique ON manifest_index ( |
| 179 | + package_id, |
| 180 | + COALESCE(dist_id, 0), |
| 181 | + COALESCE(repo_id, 0), |
| 182 | + manifest_hash |
| 183 | +); |
0 commit comments