comparison schema/import_tests.sql @ 4126:52f7264265bb

Bulk-delete tracked entries per table Especially when many entries in one table are tracked by one import, this makes declining an import a lot faster.
author Tom Gottfried <tom@intevation.de>
date Thu, 01 Aug 2019 17:02:09 +0200
parents
children
comparison
equal deleted inserted replaced
4125:0f69d256fa12 4126:52f7264265bb
1 -- This is Free Software under GNU Affero General Public License v >= 3.0
2 -- without warranty, see README.md and license for details.
3
4 -- SPDX-License-Identifier: AGPL-3.0-or-later
5 -- License-Filename: LICENSES/AGPL-3.0.txt
6
7 -- Copyright (C) 2019 by via donau
8 -- – Österreichische Wasserstraßen-Gesellschaft mbH
9 -- Software engineering by Intevation GmbH
10
11 -- Author(s):
12 -- * Tom Gottfried <tom@intevation.de>
13
14 --
15 -- pgTAP test script for import queue
16 --
17
18 \set imp_id 99
19 PREPARE insert_gms AS WITH
20 gms AS (
21 INSERT INTO waterway.gauge_measurements (
22 location,
23 measure_date,
24 country_code,
25 sender,
26 language_code,
27 date_issue,
28 reference_code,
29 water_level,
30 date_info,
31 source_organization
32 ) SELECT
33 ('AT', 'XXX', '00001', 'G0001', 1)::isrs,
34 t,
35 'AT',
36 'test',
37 'DE',
38 current_timestamp,
39 'ZPG',
40 0,
41 current_timestamp,
42 'test'
43 FROM generate_series(
44 current_timestamp - '12 h'::interval,
45 current_timestamp - '6 h'::interval,
46 '15 min'::interval) AS times (t)
47 RETURNING id),
48 imps AS (
49 INSERT INTO import.imports (id, kind, username) VALUES (
50 $1, 'test', 'test_admin_ro')
51 RETURNING id)
52 INSERT INTO import.track_imports (import_id, relation, key)
53 SELECT imps.id, 'waterway.gauge_measurements', gms.id
54 FROM imps, gms;
55
56 EXECUTE insert_gms(:imp_id);
57 EXECUTE insert_gms(:imp_id + 1);
58
59 SELECT ok((SELECT count(*) FROM waterway.gauge_measurements
60 WHERE id IN(SELECT key
61 FROM import.track_imports
62 WHERE import_id IN(:imp_id, :imp_id + 1))
63 ) = (SELECT count(*)
64 FROM import.track_imports WHERE import_id IN(:imp_id, :imp_id + 1)),
65 'Tracked entries of test imports exist');
66
67 SELECT import.del_import(:imp_id);
68
69 SELECT ok(0 = (SELECT count(*) FROM waterway.gauge_measurements
70 WHERE id IN(SELECT key
71 FROM import.track_imports
72 WHERE import_id = :imp_id)),
73 'Tracked entries of first test import are deleted');
74
75 SELECT ok((SELECT count(*) FROM waterway.gauge_measurements
76 WHERE id IN(SELECT key
77 FROM import.track_imports
78 WHERE import_id = :imp_id + 1)
79 ) = (SELECT count(*)
80 FROM import.track_imports WHERE import_id = :imp_id + 1),
81 'Tracked entries of second test import still exist');