Files
OverCooked-Installer/000013_e_address_observability.up.sql
T

23 lines
1.1 KiB
SQL

ALTER TABLE e_address_rules
ADD COLUMN match_count bigint NOT NULL DEFAULT 0 CHECK (match_count >= 0),
ADD COLUMN last_matched_at timestamptz;
CREATE TABLE e_address_selection_events (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
user_id uuid REFERENCES users(id) ON DELETE SET NULL,
address_id uuid REFERENCES e_addresses(id) ON DELETE SET NULL,
rule_id uuid REFERENCES e_address_rules(id) ON DELETE SET NULL,
outcome text NOT NULL CHECK (outcome IN ('selected','unavailable','access_denied')),
reason text NOT NULL DEFAULT '',
source_ip_hash text NOT NULL DEFAULT '',
country text NOT NULL DEFAULT '',
region text NOT NULL DEFAULT '',
carrier text NOT NULL DEFAULT '',
asn bigint NOT NULL DEFAULT 0 CHECK (asn BETWEEN 0 AND 4294967295),
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX e_address_selection_events_created_idx ON e_address_selection_events(created_at DESC);
CREATE INDEX e_address_selection_events_outcome_idx ON e_address_selection_events(outcome,created_at DESC);
CREATE INDEX e_address_selection_events_user_idx ON e_address_selection_events(user_id,created_at DESC);