Skip to content

Commit a95f887

Browse files
authored
Merge pull request #248 from jspricke/fix_merge_sql
Fix merge.sql
2 parents 12ac1fb + 3c69027 commit a95f887

1 file changed

Lines changed: 32 additions & 21 deletions

File tree

contrib/scripts/merge.sql

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ ATTACH DATABASE :OTHER_DB AS other;
88
BEGIN TRANSACTION;
99

1010
-- source packages
11-
INSERT INTO source_packages (name, version, distribution, "release", component, last_seen, seen_in_last_sync)
12-
SELECT name, version, distribution, "release", component, last_seen, seen_in_last_sync
11+
INSERT INTO source_packages (name, version, distribution, "release", last_seen, seen_in_last_sync)
12+
SELECT name, version, distribution, "release", last_seen, seen_in_last_sync
1313
FROM other.source_packages
1414
WHERE TRUE
1515
ON CONFLICT DO NOTHING;
@@ -18,8 +18,8 @@ ON CONFLICT DO NOTHING;
1818
INSERT INTO build_inputs (source_package_id, url, backend, architecture, retries, next_retry)
1919
SELECT (SELECT id
2020
FROM source_packages
21-
WHERE (name, version, distribution, "release", component) IS
22-
(SELECT name, version, distribution, "release", component
21+
WHERE (name, version, distribution, "release") IS
22+
(SELECT name, version, distribution, "release"
2323
FROM other.source_packages
2424
WHERE id = other.build_inputs.source_package_id)),
2525
url,
@@ -32,23 +32,26 @@ WHERE TRUE
3232
ON CONFLICT DO NOTHING;
3333

3434
-- binary packages, mapped to source packages and build inputs
35-
INSERT INTO binary_packages (source_package_id, build_input_id, name, version, architecture, artifact_url)
35+
INSERT INTO binary_packages (source_package_id, build_input_id, name, version, component, architecture, artifact_url)
3636
SELECT (SELECT id
3737
FROM source_packages
38-
WHERE (name, version, distribution, "release", component) IS
39-
(SELECT name, version, distribution, "release", component
38+
WHERE (name, version, distribution, "release") IS
39+
(SELECT name, version, distribution, "release"
4040
FROM other.source_packages
4141
WHERE id = other.binary_packages.source_package_id)),
4242
(SELECT id
4343
FROM build_inputs
4444
WHERE source_package_id IS (SELECT id
4545
FROM source_packages
46-
WHERE (name, version, distribution, "release", component) IS
47-
(SELECT name, version, distribution, "release", component
46+
WHERE (name, version, distribution, "release") IS
47+
(SELECT name, version, distribution, "release"
4848
FROM other.source_packages
49-
WHERE id = other.binary_packages.source_package_id))),
49+
WHERE id = other.binary_packages.source_package_id))
50+
AND architecture IS other.binary_packages.architecture
51+
),
5052
name,
5153
version,
54+
component,
5255
architecture,
5356
artifact_url
5457
FROM other.binary_packages
@@ -61,15 +64,17 @@ CREATE TEMPORARY TABLE _build_log_map
6164
id INTEGER PRIMARY KEY AUTOINCREMENT,
6265
old_id INTEGER NOT NULL,
6366
new_id INTEGER
64-
)
67+
);
6568

6669
INSERT INTO _build_log_map(old_id, new_id)
6770
SELECT id, (SELECT seq FROM main.sqlite_sequence WHERE name IS 'build_logs') + rowid
6871
FROM other.build_logs
6972
ORDER BY id;
7073

71-
INSERT INTO build_logs(build_log)
72-
SELECT build_log
74+
INSERT INTO build_logs(id, build_log)
75+
SELECT
76+
(SELECT new_id FROM _build_log_map WHERE old_id IS other.build_logs.id),
77+
build_log
7378
FROM other.build_logs
7479
ORDER BY id;
7580

@@ -88,8 +93,10 @@ SELECT id, (SELECT seq FROM main.sqlite_sequence WHERE name IS 'attestation_logs
8893
FROM other.attestation_logs
8994
ORDER BY id;
9095

91-
INSERT INTO attestation_logs(attestation_log)
92-
SELECT attestation_log
96+
INSERT INTO attestation_logs(id, attestation_log)
97+
SELECT
98+
(SELECT new_id FROM _attestation_log_map WHERE old_id IS other.attestation_logs.id),
99+
attestation_log
93100
FROM other.attestation_logs
94101
ORDER BY id;
95102

@@ -108,8 +115,10 @@ SELECT id, (SELECT seq FROM main.sqlite_sequence WHERE name IS 'diffoscope_logs'
108115
FROM other.diffoscope_logs
109116
ORDER BY id;
110117

111-
INSERT INTO diffoscope_logs(diffoscope_log)
112-
SELECT diffoscope_log
118+
INSERT INTO diffoscope_logs(id, diffoscope_log)
119+
SELECT
120+
(SELECT new_id FROM _diffoscope_log_map WHERE old_id IS other.diffoscope_logs.id),
121+
diffoscope_log
113122
FROM other.diffoscope_logs
114123
ORDER BY id;
115124

@@ -127,13 +136,15 @@ SELECT id, (SELECT seq FROM main.sqlite_sequence WHERE name IS 'rebuilds') + row
127136
FROM other.rebuilds
128137
ORDER BY id;
129138

130-
INSERT INTO rebuilds (build_input_id, started_at, built_at, build_log_id, status)
131-
SELECT ( -- build_input_id in the merged db
139+
INSERT INTO rebuilds (id, build_input_id, started_at, built_at, build_log_id, status)
140+
SELECT
141+
(SELECT new_id FROM _rebuilds_map WHERE old_id IS other.rebuilds.id),
142+
( -- build_input_id in the merged db
132143
SELECT build_inputs.id
133144
FROM build_inputs
134145
INNER JOIN source_packages ON build_inputs.source_package_id = source_packages.id
135-
WHERE (name, version, distribution, "release", component) IS
136-
(SELECT name, version, distribution, "release", component
146+
WHERE (name, version, distribution, "release", architecture) IS
147+
(SELECT name, version, distribution, "release", architecture
137148
FROM other.source_packages
138149
INNER JOIN other.build_inputs
139150
ON other.source_packages.id IS other.build_inputs.source_package_id

0 commit comments

Comments
 (0)