File size: 1,044 Bytes
870fd80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-- riskgate (PostgreSQL 15)

CREATE TABLE accounts (
    id            bigint PRIMARY KEY,
    created_at    timestamptz NOT NULL,
    status        text NOT NULL CHECK (status IN ('active', 'frozen', 'confirmed_fraud', 'closed'))
);

CREATE TABLE entities (
    id      bigint PRIMARY KEY,
    kind    text NOT NULL CHECK (kind IN ('device', 'card', 'address', 'phone')),
    digest  bytea NOT NULL,
    UNIQUE (kind, digest)
);

-- An account used an entity. Written by the event consumer as activity happens.
CREATE TABLE links (
    account_id  bigint NOT NULL REFERENCES accounts (id),
    entity_id   bigint NOT NULL REFERENCES entities (id),
    first_seen  timestamptz NOT NULL,
    last_seen   timestamptz NOT NULL,
    PRIMARY KEY (account_id, entity_id)
);
CREATE INDEX links_entity_account_idx ON links (entity_id, account_id);

-- Maintained by the event consumer; used to skip very widely shared entities.
CREATE TABLE entity_degree (
    entity_id  bigint PRIMARY KEY REFERENCES entities (id),
    accounts   integer NOT NULL
);