view schema/import_tests.sql @ 5560:f2204f91d286

Join the log lines of imports to the log exports to recover data from them. Used in SR export to extract information that where in the meta json but now are only found in the log.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 09 Feb 2022 18:34:40 +0100
parents 52f7264265bb
children
line wrap: on
line source

-- This is Free Software under GNU Affero General Public License v >= 3.0
-- without warranty, see README.md and license for details.

-- SPDX-License-Identifier: AGPL-3.0-or-later
-- License-Filename: LICENSES/AGPL-3.0.txt

-- Copyright (C) 2019 by via donau
--   – Österreichische Wasserstraßen-Gesellschaft mbH
-- Software engineering by Intevation GmbH

-- Author(s):
--  * Tom Gottfried <tom@intevation.de>

--
-- pgTAP test script for import queue
--

\set imp_id 99
PREPARE insert_gms AS WITH
gms AS (
    INSERT INTO waterway.gauge_measurements (
        location,
        measure_date,
        country_code,
        sender,
        language_code,
        date_issue,
        reference_code,
        water_level,
        date_info,
        source_organization
    ) SELECT
            ('AT', 'XXX', '00001', 'G0001', 1)::isrs,
            t,
            'AT',
            'test',
            'DE',
            current_timestamp,
            'ZPG',
            0,
            current_timestamp,
            'test'
        FROM generate_series(
            current_timestamp - '12 h'::interval,
            current_timestamp - '6 h'::interval,
            '15 min'::interval) AS times (t)
    RETURNING id),
imps AS (
    INSERT INTO import.imports (id, kind, username) VALUES (
        $1, 'test', 'test_admin_ro')
    RETURNING id)
INSERT INTO import.track_imports (import_id, relation, key)
    SELECT imps.id, 'waterway.gauge_measurements', gms.id
           FROM imps, gms;

EXECUTE insert_gms(:imp_id);
EXECUTE insert_gms(:imp_id + 1);

SELECT ok((SELECT count(*) FROM waterway.gauge_measurements
        WHERE id IN(SELECT key
            FROM import.track_imports
            WHERE import_id IN(:imp_id, :imp_id + 1))
    ) = (SELECT count(*)
        FROM import.track_imports WHERE import_id IN(:imp_id, :imp_id + 1)),
    'Tracked entries of test imports exist');

SELECT import.del_import(:imp_id);

SELECT ok(0 = (SELECT count(*) FROM waterway.gauge_measurements
        WHERE id IN(SELECT key
            FROM import.track_imports
            WHERE import_id = :imp_id)),
    'Tracked entries of first test import are deleted');

SELECT ok((SELECT count(*) FROM waterway.gauge_measurements
        WHERE id IN(SELECT key
            FROM import.track_imports
            WHERE import_id = :imp_id + 1)
    ) = (SELECT count(*)
        FROM import.track_imports WHERE import_id = :imp_id + 1),
    'Tracked entries of second test import still exist');