Files
ITWorx-Pulse-Public/internal/database/migrations/0002_inventory.sql
T
ITWorx Pulse release export bd774932d5
Public source validation / validate (push) Failing after 3m8s
Publish ITWorx Pulse source
2026-09-03 02:09:19 +02:00

37 lines
1.5 KiB
SQL

CREATE TABLE entity_facts (
entity_id uuid NOT NULL REFERENCES entities(id) ON DELETE CASCADE,
field_name text NOT NULL,
source_id uuid NOT NULL REFERENCES data_sources(id) ON DELETE CASCADE,
value jsonb NOT NULL,
observed_at timestamptz NOT NULL,
confidence numeric(5,4) NOT NULL CHECK (confidence >= 0 AND confidence <= 1),
valid_until timestamptz,
PRIMARY KEY (entity_id, field_name, source_id)
);
CREATE TABLE entity_overrides (
entity_id uuid NOT NULL REFERENCES entities(id) ON DELETE CASCADE,
field_name text NOT NULL,
value jsonb NOT NULL,
user_id uuid REFERENCES users(id) ON DELETE SET NULL,
updated_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (entity_id, field_name)
);
CREATE TABLE entity_relations (
id uuid PRIMARY KEY,
source_entity_id uuid NOT NULL REFERENCES entities(id) ON DELETE CASCADE,
relation_type text NOT NULL,
target_entity_id uuid NOT NULL REFERENCES entities(id) ON DELETE CASCADE,
source_id uuid NOT NULL REFERENCES data_sources(id) ON DELETE CASCADE,
confidence numeric(5,4) NOT NULL CHECK (confidence >= 0 AND confidence <= 1),
confirmed boolean NOT NULL DEFAULT false,
first_seen_at timestamptz NOT NULL,
last_seen_at timestamptz,
tombstoned_at timestamptz,
UNIQUE (source_entity_id, relation_type, target_entity_id, source_id)
);
CREATE INDEX entity_facts_source_observed_idx ON entity_facts (source_id, observed_at DESC);
CREATE INDEX entity_relations_source_idx ON entity_relations (source_id, last_seen_at DESC);