CREATE TABLE IF NOT EXISTS audits ( id BIGSERIAL PRIMARY KEY, account_id BIGINT NOT NULL, user_id BIGINT, auditable_type VARCHAR(100) NOT NULL, auditable_id BIGINT NOT NULL, action VARCHAR(50) NOT NULL, audited_changes JSONB DEFAULT '{}'::jsonb, associated_type VARCHAR(100), associated_id BIGINT, username VARCHAR(255), remote_address VARCHAR(100), request_uuid VARCHAR(100), version BIGINT, comment TEXT, user_type VARCHAR(50), created_at TIMESTAMPTZ ); CREATE INDEX IF NOT EXISTS idx_audits_account_id ON audits (account_id); CREATE INDEX IF NOT EXISTS idx_audits_user_id ON audits (user_id); CREATE INDEX IF NOT EXISTS idx_audits_action ON audits (action); CREATE INDEX IF NOT EXISTS idx_audits_auditable ON audits (auditable_type, auditable_id); CREATE INDEX IF NOT EXISTS idx_audits_associated ON audits (associated_type, associated_id); CREATE INDEX IF NOT EXISTS idx_audits_created_at ON audits (created_at);