|
| 1 | +-- User table: Stores user information |
| 2 | +CREATE TABLE IF NOT EXISTS "User" ( |
| 3 | + id SERIAL PRIMARY KEY, |
| 4 | + telegram_id BIGINT UNIQUE NOT NULL, -- Telegram user ID |
| 5 | + username TEXT DEFAULT NULL, |
| 6 | + first_name TEXT, |
| 7 | + role TEXT CHECK (role IN ('admin','owner', 'user', 'approved_user')), -- User roles for managing permissions |
| 8 | + warnings INT DEFAULT 0, -- Number of warnings the user has received |
| 9 | + approved_groups BIGINT[] -- Array of approved group IDs for the user |
| 10 | +); |
| 11 | + |
1 | 12 | -- Group table: Stores information about groups managed by the bot |
2 | | -CREATE TABLE Group ( |
| 13 | +CREATE TABLE IF NOT EXISTS "Group" ( |
3 | 14 | id SERIAL PRIMARY KEY, |
4 | 15 | group_id BIGINT UNIQUE NOT NULL, -- Telegram group ID |
5 | 16 | group_name TEXT, |
6 | 17 | rules TEXT[], -- Array of rules for the group |
7 | | - added_by_id BIGINT REFERENCES User(id), -- ID of the admin who added the group |
8 | 18 | black_list TEXT[], -- Array of blacklisted words or users |
9 | 19 | chat_permissions JSONB, -- JSON to store permissions |
10 | 20 | updated_at TIMESTAMP DEFAULT NOW(), |
11 | 21 | joined_at TIMESTAMP DEFAULT NOW(), |
12 | 22 | approved_users BIGINT[], -- Array of approved user IDs |
13 | | - warnings INT DEFAULT 0, -- Number of warnings in the group |
| 23 | + warnings BIGINT[], -- Number of warnings in the group |
14 | 24 | is_spam_time BOOLEAN DEFAULT FALSE, -- Flag for spam detection |
15 | | - members INT -- Number of members in the group |
16 | | -); |
17 | | - |
18 | | --- User table: Stores user information |
19 | | -CREATE TABLE User ( |
20 | | - id SERIAL PRIMARY KEY, |
21 | | - telegram_id BIGINT UNIQUE NOT NULL, -- Telegram user ID |
22 | | - username TEXT, |
23 | | - role TEXT CHECK (role IN ('admin', 'user', 'moderator')), -- User roles for managing permissions |
24 | | - warnings INT DEFAULT 0, -- Number of warnings the user has received |
25 | | - approved_groups BIGINT[] -- Array of approved group IDs for the user |
| 25 | + members BIGINT[] |
26 | 26 | ); |
27 | 27 |
|
28 | 28 | -- Warning table: Stores information on user warnings |
29 | | -CREATE TABLE Warning ( |
| 29 | +CREATE TABLE IF NOT EXISTS "Warning" ( |
30 | 30 | id SERIAL PRIMARY KEY, |
31 | | - user_id BIGINT REFERENCES User(id), -- User who was warned |
32 | | - group_id BIGINT REFERENCES Group(id), -- Group where the warning was issued |
| 31 | + user_id BIGINT REFERENCES "User"(id), -- User who was warned |
| 32 | + group_id BIGINT REFERENCES "Group"(id), -- Group where the warning was issued |
33 | 33 | warned_at TIMESTAMP DEFAULT NOW(), |
34 | 34 | reason TEXT |
35 | 35 | ); |
36 | 36 |
|
37 | 37 | -- ApprovedUser table: Tracks users approved in specific groups |
38 | | -CREATE TABLE ApprovedUser ( |
| 38 | +CREATE TABLE IF NOT EXISTS "ApprovedUser" ( |
39 | 39 | id SERIAL PRIMARY KEY, |
40 | | - user_id BIGINT REFERENCES User(id), -- User who was approved |
41 | | - group_id BIGINT REFERENCES Group(id), -- Group where the user was approved |
| 40 | + user_id BIGINT REFERENCES "User"(id), -- User who was approved |
| 41 | + group_id BIGINT REFERENCES "Group"(id), -- Group where the user was approved |
42 | 42 | username TEXT, |
43 | 43 | approved_at TIMESTAMP DEFAULT NOW() |
44 | 44 | ); |
45 | 45 |
|
46 | 46 | -- Channel table: Stores channel details managed by the bot |
47 | | -CREATE TABLE Channel ( |
| 47 | +CREATE TABLE IF NOT EXISTS "Channel" ( |
48 | 48 | id SERIAL PRIMARY KEY, |
49 | 49 | name TEXT, |
50 | 50 | channel_id BIGINT UNIQUE NOT NULL, -- Telegram channel ID |
51 | 51 | admins BIGINT[] -- Array of admin user IDs for the channel |
52 | 52 | ); |
53 | 53 |
|
54 | | --- GroupAdminPermissions table: Defines admin permissions for specific groups |
55 | | -CREATE TABLE GroupAdminPermissions ( |
56 | | - id SERIAL PRIMARY KEY, |
57 | | - group_id BIGINT REFERENCES Group(id), |
58 | | - user_id BIGINT REFERENCES User(id), |
59 | | - can_manage_approvals BOOLEAN DEFAULT FALSE, |
60 | | - can_manage_users BOOLEAN DEFAULT FALSE, |
61 | | - can_manage_blacklist BOOLEAN DEFAULT FALSE, |
62 | | - can_manage_rules BOOLEAN DEFAULT FALSE, |
63 | | - can_manage_pinning BOOLEAN DEFAULT FALSE, |
64 | | - can_manage_messages BOOLEAN DEFAULT FALSE, |
65 | | - can_manage_group_settings BOOLEAN DEFAULT FALSE, |
66 | | - can_view_group_stats BOOLEAN DEFAULT FALSE, |
67 | | - can_broadcast_message BOOLEAN DEFAULT FALSE, |
68 | | - can_view_admin_list BOOLEAN DEFAULT FALSE |
69 | | -); |
70 | | - |
71 | 54 | -- Blacklist table: Stores blacklisted words and users for each group |
72 | | -CREATE TABLE Blacklist ( |
| 55 | +CREATE TABLE IF NOT EXISTS "Blacklist" ( |
73 | 56 | id SERIAL PRIMARY KEY, |
74 | | - group_id BIGINT REFERENCES Group(id), |
| 57 | + group_id BIGINT REFERENCES "Group"(id), |
75 | 58 | blacklisted_word TEXT, -- Word to be blacklisted |
76 | | - blacklisted_user_id BIGINT REFERENCES User(id) -- User to be blacklisted |
| 59 | + blacklisted_user_id BIGINT REFERENCES "User"(id) -- User to be blacklisted |
77 | 60 | ); |
78 | 61 |
|
79 | 62 | -- GroupRule table: Stores individual rules for each group |
80 | | -CREATE TABLE GroupRule ( |
| 63 | +CREATE TABLE IF NOT EXISTS "GroupRule" ( |
81 | 64 | id SERIAL PRIMARY KEY, |
82 | | - group_id BIGINT REFERENCES Group(id), |
| 65 | + group_id BIGINT REFERENCES "Group"(id), |
83 | 66 | rule_text TEXT, -- Text of the rule |
84 | 67 | added_at TIMESTAMP DEFAULT NOW(), |
85 | | - added_by BIGINT REFERENCES User(id) |
| 68 | + added_by BIGINT REFERENCES "User"(id) |
86 | 69 | ); |
87 | 70 |
|
88 | 71 | -- GroupMessageSettings table: Stores group message settings (e.g., slow mode) |
89 | | -CREATE TABLE GroupMessageSettings ( |
| 72 | +CREATE TABLE IF NOT EXISTS "GroupMessageSettings" ( |
90 | 73 | id SERIAL PRIMARY KEY, |
91 | | - group_id BIGINT REFERENCES Group(id), |
| 74 | + group_id BIGINT REFERENCES "Group"(id), |
92 | 75 | is_locked BOOLEAN DEFAULT FALSE, |
93 | 76 | welcome_message TEXT, |
94 | 77 | last_updated TIMESTAMP DEFAULT NOW() |
|
0 commit comments