diff options
| author | Masaya Tojo <masaya@tojo.tokyo> | 2023-03-12 18:24:31 +0900 | 
|---|---|---|
| committer | Masaya Tojo <masaya@tojo.tokyo> | 2023-03-12 23:38:13 +0900 | 
| commit | d5ebc30b1092a89e364720b2d302b1978d62632c (patch) | |
| tree | 18a3793dd83726beb14fb036928fceac93ad3be0 /verify | |
| parent | baaa9bb106af01c0d6d5fd9cde87a27852bb8622 (diff) | |
Add function to delete transaction.
Diffstat (limited to 'verify')
| -rw-r--r-- | verify/delete_transaction.sql | 43 | 
1 files changed, 43 insertions, 0 deletions
| diff --git a/verify/delete_transaction.sql b/verify/delete_transaction.sql new file mode 100644 index 0000000..9f4d1d8 --- /dev/null +++ b/verify/delete_transaction.sql @@ -0,0 +1,43 @@ +-- Verify kakeibo:delete_transaction on pg + +BEGIN; + +SELECT has_function_privilege('kakeibo.delete_transaction(INTEGER)', 'EXECUTE'); + +SET search_path = kakeibo; + +DO $$ +  DECLARE +    v_transaction_id INTEGER; +    v_transaction_id_2 INTEGER; +    v_item_id INTEGER; +  BEGIN +    SELECT insert_transaction(0, '2023-03-15', 'テスト') INTO v_transaction_id; +    SELECT insert_transaction(1, '2023-03-15', 'テスト2') INTO v_transaction_id_2; +    SELECT insert_item(v_transaction_id, 'カテ', 'サブカテ', 298, 'メモ') INTO v_item_id; + +    BEGIN +      PERFORM delete_transaction(v_transaction_id); +    EXCEPTION +      WHEN foreign_key_violation THEN +    END; +    PERFORM * FROM transactions WHERE id = v_transaction_id; +    IF NOT FOUND THEN +      RAISE EXCEPTION 'Unexpected delete data.'; +    END IF; + +    PERFORM delete_item(v_item_id); +    PERFORM delete_transaction(v_transaction_id); +    PERFORM * FROM transactions WHERE id = v_transaction_id; +    IF FOUND THEN +      RAISE EXCEPTION 'Deleted data still exists.'; +    END IF; + +    PERFORM * FROM transactions WHERE id = v_transaction_id_2; +    IF NOT FOUND THEN +      RAISE EXCEPTION 'Unexpected delete data.'; +    END IF; +  END +$$; + +ROLLBACK; | 
