forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path008_create_contract_events.sql
More file actions
23 lines (21 loc) · 1.13 KB
/
Copy path008_create_contract_events.sql
File metadata and controls
23 lines (21 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- Migration 008: Create contract_events table for audit logging
-- Requirements: #182
CREATE TABLE IF NOT EXISTS contract_events (
id SERIAL PRIMARY KEY,
contract_id VARCHAR(64) NOT NULL,
event_type VARCHAR(50) NOT NULL CHECK (event_type IN ('mint', 'claim', 'stake', 'unstake')),
event_data JSONB NOT NULL,
transaction_hash VARCHAR(64),
ledger_sequence INTEGER,
processed_at TIMESTAMPTZ,
retry_count INTEGER DEFAULT 0,
status VARCHAR(20) DEFAULT 'pending' CHECK (status IN ('pending', 'processed', 'failed')),
error_message TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- Indexes for efficient querying
CREATE INDEX IF NOT EXISTS idx_contract_events_contract_id ON contract_events (contract_id);
CREATE INDEX IF NOT EXISTS idx_contract_events_type ON contract_events (event_type);
CREATE INDEX IF NOT EXISTS idx_contract_events_status ON contract_events (status);
CREATE INDEX IF NOT EXISTS idx_contract_events_created_at ON contract_events (created_at);
CREATE INDEX IF NOT EXISTS idx_contract_events_processed_at ON contract_events (processed_at);