-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsps.sql
More file actions
36 lines (32 loc) · 1.12 KB
/
sps.sql
File metadata and controls
36 lines (32 loc) · 1.12 KB
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
CREATE SCHEMA sps;
-- \dn list schemas
-- spsdata=> \dt sps.*
-- List of relations
-- Schema | Name | Type | Owner
-- --------+-------------+-------+--------
-- sps | opinions | table | jerkey
-- sps | screedlines | table | jerkey
-- sps | screeds | table | jerkey
-- https://www.postgresql.org/docs/current/datatype-numeric.html
CREATE TABLE sps.screeds (
pubkey VARCHAR(64) NOT NULL PRIMARY KEY,
signer_key VARCHAR(64) NOT NULL,
sig_expires TIMESTAMPZ NOT NULL,
modified TIMESTAMPZ NOT NULL
);
-- SELECT * FROM sps.opinions;
CREATE TABLE sps.opinions (
id SERIAL PRIMARY KEY,
opinion TEXT NOT NULL,
screed_count INTEGER,
updated_at TIMESTAMPZ NOT NULL DEFAULT CURRENT_TIMESTAMPZ
);
CREATE TABLE sps.screedlines (
id SERIAL PRIMARY KEY,
screed_key VARCHAR(64) NOT NULL,
opinion_id INTEGER NOT NULL,
FOREIGN KEY (screed_key) REFERENCES sps.screeds(pubkey),
FOREIGN KEY (opinion_id) REFERENCES sps.opinions(id)
);
-- This will ensure only one copy of each opinion exists
ALTER TABLE sps.opinions ADD CONSTRAINT unique_opinion UNIQUE (opinion);