yeagerai / genlayer-simulator

MIT License
8 stars 2 forks source link

Simulator - Add transactions audit table #150

Open cristiam86 opened 1 month ago

cristiam86 commented 1 month ago

New table called "rollup"/"audit" with all the transaction states.

sevenearths commented 1 month ago

@cristiam86 any more information you can give me on this ticket?

sevenearths commented 1 month ago

Schema:

sevenearths commented 1 month ago

Use the new database files for all of this => https://github.com/yeagerai/genlayer-simulator/blob/main/database/functions.py

sevenearths commented 1 month ago

Inserts will happen to the audit table when:

sevenearths commented 1 month ago

After looking into the following two options:

(*)

-- Create a function to log changes
CREATE OR REPLACE FUNCTION log_transaction_changes() RETURNS TRIGGER AS $$
BEGIN
    IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
        PERFORM pgaudit.audit_function('WRITE');
    END IF;
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

-- Create a trigger on the transactions table
CREATE TRIGGER audit_transaction_changes
AFTER INSERT OR UPDATE ON transactions
FOR EACH ROW EXECUTE FUNCTION log_transaction_changes();