-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathschema.sql
More file actions
25 lines (22 loc) · 798 Bytes
/
schema.sql
File metadata and controls
25 lines (22 loc) · 798 Bytes
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
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE IF NOT EXISTS pastes (
id TEXT PRIMARY KEY,
created_at TIMESTAMP NOT NULL DEFAULT (NOW() AT TIME ZONE 'UTC'),
expires TIMESTAMP WITH TIME ZONE,
password TEXT DEFAULT NULL,
views INTEGER DEFAULT 0,
safety TEXT UNIQUE
);
CREATE UNIQUE INDEX IF NOT EXISTS pastes_safety_idx ON pastes (safety);
-- Index by safety keys for faster lookup to delete.
CREATE TABLE IF NOT EXISTS files (
parent_id TEXT REFERENCES pastes(id) ON DELETE CASCADE,
content TEXT NOT NULL,
filename TEXT NOT NULL,
loc INTEGER NOT NULL,
charcount INTEGER GENERATED ALWAYS AS (LENGTH(content)) STORED,
file_index SERIAL NOT NULL,
annotation TEXT,
warning_positions INTEGER[],
PRIMARY KEY (parent_id, file_index)
);