-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.sql
More file actions
69 lines (61 loc) · 2.33 KB
/
Copy pathinit.sql
File metadata and controls
69 lines (61 loc) · 2.33 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-- Init script for Docker Postgres.
-- POSTGRES_USER=discord_bot and POSTGRES_DB=discord_events are set via env,
-- so role/database creation and \connect are handled by the image automatically.
CREATE TABLE IF NOT EXISTS users (
discord_user_id TEXT PRIMARY KEY,
username TEXT,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS channels (
discord_channel_id TEXT PRIMARY KEY,
channel_name TEXT,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS events (
id BIGSERIAL PRIMARY KEY,
discord_channel_id TEXT REFERENCES channels(discord_channel_id),
discord_message_id TEXT,
emoji TEXT,
date TIMESTAMPTZ,
title TEXT,
location TEXT,
price TEXT,
description TEXT,
author_id TEXT,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS event_responses (
id BIGSERIAL PRIMARY KEY,
event_id BIGINT REFERENCES events(id),
user_id TEXT,
response_type TEXT CHECK (response_type IN ('yes', 'no', 'maybe')),
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
UNIQUE (event_id, user_id)
);
CREATE TABLE IF NOT EXISTS commands (
id BIGSERIAL PRIMARY KEY,
discord_user_id TEXT REFERENCES users(discord_user_id),
command_text TEXT,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS messages (
discord_message_id TEXT PRIMARY KEY,
discord_channel_id TEXT,
discord_user_id TEXT,
message TEXT,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS poker_sessions (
id BIGSERIAL PRIMARY KEY,
user_id TEXT NOT NULL,
in_amount NUMERIC(14,2) NOT NULL CHECK (in_amount >= 0),
out_amount NUMERIC(14,2) NOT NULL CHECK (out_amount >= 0),
location TEXT,
stakes_sb NUMERIC(10,2),
stakes_bb NUMERIC(10,2),
stakes_text TEXT,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO discord_bot;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO discord_bot;