-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB.SQL
More file actions
36 lines (30 loc) · 1.11 KB
/
Copy pathDB.SQL
File metadata and controls
36 lines (30 loc) · 1.11 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 EXTENSION IF NOT EXISTS "pgcrypto";
CREATE TABLE IF NOT EXISTS users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
username VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
created TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS invalid_tokens (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
token TEXT UNIQUE NOT NULL,
expires TIMESTAMPTZ NOT NULL
);
CREATE TABLE IF NOT EXISTS catheters (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
started_at TIMESTAMPTZ NOT NULL,
ended_at TIMESTAMPTZ DEFAULT NULL,
change_reason smallint DEFAULT 0 NOT NULL,
CHECK (change_reason >= 0)
CHECK (ended_at IS NULL OR ended_at > started_at)
);
-- Migration from 1.0.x to 1.1.x --
CREATE TABLE IF NOT EXISTS invalid_tokens (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
token TEXT UNIQUE NOT NULL,
expires TIMESTAMPTZ NOT NULL
);
-- the old sessions table can be deletet, it's no longer used
ALTER TABLE catheters
ADD COLUMN change_reason smallint DEFAULT 0 NOT NULL;