-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sql
49 lines (42 loc) · 1.32 KB
/
setup.sql
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
CREATE TABLE IF NOT EXISTS telem (
ts TIMESTAMP,
device VARCHAR(50),
msg JSONB,
prio VARCHAR(8),
ec VARCHAR(20),
PRIMARY KEY (ts, device, msg)
);
CREATE INDEX IF NOT EXISTS telem_device_ts ON telem (device, ts);
CREATE TABLE IF NOT EXISTS logs (
ts TIMESTAMP,
device VARCHAR(50),
msg JSONB,
prio VARCHAR(8),
ec VARCHAR(20),
PRIMARY KEY(ts, device, msg)
);
CREATE INDEX IF NOT EXISTS logs_device_ts ON logs (device, ts);
CREATE TABLE IF NOT EXISTS file_inventory (
origin_host VARCHAR(50),
origin_path VARCHAR(1024),
modification_time TIMESTAMP,
size_bytes INTEGER,
PRIMARY KEY (origin_host, origin_path)
);
CREATE TABLE IF NOT EXISTS file_ingest_times (
ts TIMESTAMP,
device VARCHAR(50),
ingested_at TIMESTAMP,
origin_host VARCHAR(50),
origin_path VARCHAR(1024),
FOREIGN KEY (origin_host, origin_path) REFERENCES file_inventory (origin_host, origin_path)
);
CREATE TABLE IF NOT EXISTS file_replicas (
hostname VARCHAR(50),
replica_path VARCHAR(1024),
origin_modification_time TIMESTAMP, -- intentionally denormalized because replicas may lag behind originals
size_bytes INTEGER,
origin_host VARCHAR(50),
origin_path VARCHAR(1024),
FOREIGN KEY (origin_host, origin_path) REFERENCES file_inventory (origin_host, origin_path)
);