Fix wallet_updated_at_trigger on wallet delete (#2394)

This commit is contained in:
ekzyis 2025-08-05 00:07:47 +02:00 committed by GitHub
parent 39bbaf2942
commit cbc41c0d99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,23 @@
-- fix trigger when wallet is deleted
CREATE OR REPLACE FUNCTION wallet_updated_at_trigger() RETURNS TRIGGER AS $$
DECLARE
user_id INT;
BEGIN
IF TG_TABLE_NAME = 'WalletProtocol' THEN
SELECT w."userId" INTO user_id
FROM "Wallet" w
WHERE w.id = CASE
WHEN TG_OP = 'DELETE' THEN OLD."walletId"
ELSE NEW."walletId"
END;
ELSE
user_id := CASE WHEN TG_OP = 'DELETE' THEN OLD."userId" ELSE NEW."userId" END;
END IF;
UPDATE "users" u
SET "walletsUpdatedAt" = NOW()
WHERE u.id = user_id;
RETURN NULL;
END;
$$ LANGUAGE plpgsql;