23 lines
990 B
SQL
23 lines
990 B
SQL
CREATE TABLE business_audit_events (
|
|
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
occurred_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
|
|
service VARCHAR(40) NOT NULL,
|
|
action VARCHAR(80) NOT NULL,
|
|
entity_type VARCHAR(40) NOT NULL,
|
|
entity_id BIGINT NOT NULL,
|
|
actor_id BIGINT NOT NULL,
|
|
actor_name VARCHAR(600) NOT NULL,
|
|
case_id BIGINT,
|
|
before_values JSONB NOT NULL,
|
|
after_values JSONB NOT NULL,
|
|
reason VARCHAR(500),
|
|
operation_id UUID NOT NULL,
|
|
request_id VARCHAR(128),
|
|
format_version INTEGER NOT NULL DEFAULT 1 CHECK (format_version=1)
|
|
);
|
|
CREATE INDEX business_audit_entity_idx ON business_audit_events(entity_type,entity_id,id DESC);
|
|
CREATE INDEX business_audit_case_idx ON business_audit_events(case_id,id DESC);
|
|
CREATE INDEX business_audit_actor_idx ON business_audit_events(actor_id,id DESC);
|
|
CREATE INDEX business_audit_date_idx ON business_audit_events(occurred_at,id DESC);
|
|
CREATE INDEX business_audit_operation_idx ON business_audit_events(operation_id,id);
|