Полировка кода

This commit is contained in:
2026-02-28 22:12:22 +03:00
parent 33110eed48
commit d6fed5c7b9
6 changed files with 105 additions and 30 deletions
+29
View File
@@ -9,6 +9,8 @@ DECLARE
v_prev_ts timestamp;
v_src_count bigint;
v_stg_count bigint;
v_dup_count bigint;
v_null_amount_count bigint;
BEGIN
-- Опорная метка: максимум src_created_at_ts среди предыдущих батчей
SELECT max(src_created_at_ts)
@@ -42,6 +44,33 @@ BEGIN
v_stg_count;
END IF;
-- Проверка на дубликаты book_ref
SELECT COUNT(*) - COUNT(DISTINCT book_ref)
INTO v_dup_count
FROM stg.bookings AS b
WHERE b.batch_id = v_batch_id;
IF v_dup_count <> 0 THEN
RAISE EXCEPTION
'DQ FAILED: найдены дубликаты book_ref (batch_id=%): %',
v_batch_id,
v_dup_count;
END IF;
-- Проверка на NULL или пустые total_amount
SELECT COUNT(*)
INTO v_null_amount_count
FROM stg.bookings AS b
WHERE b.batch_id = v_batch_id
AND (b.total_amount IS NULL OR b.total_amount = '');
IF v_null_amount_count <> 0 THEN
RAISE EXCEPTION
'DQ FAILED: найдены bookings с NULL или пустым total_amount (batch_id=%): %',
v_batch_id,
v_null_amount_count;
END IF;
RAISE NOTICE
'Проверка количества строк пройдена: источник=%, stg=%',
v_src_count,