Repository navigation
Expand file tree
/
Copy pathdbSetup.js
More file actions
212 lines (187 loc) · 7.21 KB
/
Copy pathdbSetup.js
File metadata and controls
212 lines (187 loc) · 7.21 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
const mysql = require('mysql2');
const config = require('./config_setup.json');
const { categoryNameMaxLen, categoryDescMaxLen, eventCodeLen, eventTitleMaxLen, tagNameMaxLen, tagContentMaxLen,
worldNameMaxLen, releaseLinkMaxLen } = require('./lib');
const guildData = `CREATE TABLE IF NOT EXISTS guild_data (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guildId VARCHAR(64) NOT NULL UNIQUE,
leadModRoleId VARCHAR(64) NOT NULL,
moderatorRoleId VARCHAR(64)
)`;
const roleSystems = `CREATE TABLE IF NOT EXISTS role_systems (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guildDataId BIGINT NOT NULL UNIQUE,
roleRequestChannelId VARCHAR(64) NOT NULL
)`;
const roleCategories = `CREATE TABLE IF NOT EXISTS role_categories (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
roleSystemId BIGINT NOT NULL,
categoryName VARCHAR(${categoryNameMaxLen}) NOT NULL,
messageId VARCHAR(64) NOT NULL
)`;
const roles = `CREATE TABLE IF NOT EXISTS roles (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
categoryId BIGINT NOT NULL,
roleId VARCHAR(64) NOT NULL UNIQUE KEY,
reaction VARCHAR(128) NOT NULL,
description VARCHAR(${categoryDescMaxLen}),
position TINYINT(2) NOT NULL
)`;
const roomSystems = `CREATE TABLE IF NOT EXISTS room_systems (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guildDataId BIGINT NOT NULL,
channelCategoryId VARCHAR(64) NOT NULL,
newGameChannelId VARCHAR(64) NOT NULL
)`;
const roomSystemChannels = `CREATE TABLE IF NOT EXISTS room_system_channels (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
roomSystemId BIGINT NOT NULL,
voiceChannelId VARCHAR(64) NOT NULL,
ownerUserId VARCHAR(64) NOT NULL,
controlMessageId VARCHAR(64) NOT NULL
)`;
const scheduledEvents = `CREATE TABLE IF NOT EXISTS scheduled_events (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guildDataId BIGINT NOT NULL,
timestamp BIGINT NOT NULL,
channelId VARCHAR(64) NOT NULL,
messageId VARCHAR(64) NOT NULL,
threadId VARCHAR(64),
schedulingUserId VARCHAR(64) NOT NULL,
eventCode VARCHAR(${eventCodeLen}) NOT NULL,
title VARCHAR(${eventTitleMaxLen}),
duration BIGINT UNSIGNED
)`;
const eventRspv = `CREATE TABLE IF NOT EXISTS event_rsvp (
id BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
eventId BIGINT UNSIGNED NOT NULL,
userId VARCHAR(64) NOT NULL,
UNIQUE eventUser(eventId, userId)
)`;
const modContact = `CREATE TABLE IF NOT EXISTS mod_contact (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guildDataId BIGINT NOT NULL,
categoryId VARCHAR(64) NOT NULL,
channelId VARCHAR(64) NOT NULL,
messageId VARCHAR(64) NOT NULL
)`;
const modContactChannels = `CREATE TABLE IF NOT EXISTS mod_contact_channels (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
modContactId BIGINT NOT NULL,
userId VARCHAR(64) NOT NULL,
reportChannelId VARCHAR(64) NOT NULL,
reportTime BIGINT NOT NULL DEFAULT (UNIX_TIMESTAMP()),
resolved TINYINT(1) NOT NULL DEFAULT 0,
resolutionTime BIGINT
)`;
const messageTags = `CREATE TABLE IF NOT EXISTS message_tags (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
tagName VARCHAR(${tagNameMaxLen}) NOT NULL UNIQUE KEY,
tagContent TEXT(${tagContentMaxLen}) NOT NULL,
createdByUserId VARCHAR(64) NOT NULL,
createdTime BIGINT NOT NULL DEFAULT (UNIX_TIMESTAMP()),
visibilityType TINYINT(1) NOT NULL DEFAULT -1, -- global=-1, regular=0, nsfw=1
)`;
const tagAliases = `CREATE TABLE IF NOT EXISTS tag_aliases (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
tagId BIGINT NOT NULL,
alias VARCHAR(${tagNameMaxLen}) NOT NULL
)`;
const guildOptions = `CREATE TABLE IF NOT EXISTS guild_options (
id BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
guildDataId BIGINT UNSIGNED NOT NULL,
eventThreads TINYINT(1) NOT NULL DEFAULT 0,
roleWhitelist TINYINT(1) NOT NULL DEFAULT 0,
messageHistoryChannelId VARCHAR(64),
alertsChannelId VARCHAR(64),
spamPurge TINYINT(1) NOT NULL DEFAULT 0,
UNIQUE KEY guildDataId (guildDataId)
)`;
const pingableRoles = `CREATE TABLE IF NOT EXISTS pingable_roles (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guildDataId BIGINT NOT NULL,
roleId VARCHAR(64) NOT NULL,
UNIQUE KEY guildDataId (guildDataId, roleId)
)`;
const threadManagement = `CREATE TABLE IF NOT EXISTS thread_management (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guildDataId BIGINT UNSIGNED NOT NULL,
channelId VARCHAR(64) NOT NULL,
userId VARCHAR(64) NOT NULL,
UNIQUE KEY guildChannelUser (guildDataId, channelId, userId)
)`;
// Effectively storing a set, maybe there's a better way to do this
const alertedThreads = `CREATE TABLE IF NOT EXISTS alerted_threads (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
threadId VARCHAR(64) UNIQUE KEY NOT NULL
)`;
const pinnedForumPosts = `CREATE TABLE IF NOT EXISTS pinned_forum_posts (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
channelId VARCHAR(64) UNIQUE KEY NOT NULL,
postId VARCHAR(64) UNIQUE KEY NOT NULL
)`;
const scheduleBoards = `CREATE TABLE IF NOT EXISTS schedule_boards (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guildDataId BIGINT NOT NULL,
channelId VARCHAR(64) NOT NULL,
messageId VARCHAR(64) NOT NULL
)`;
const apworldInfo = `CREATE TABLE IF NOT EXISTS apworld_info (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
worldName VARCHAR(${worldNameMaxLen}) NOT NULL,
releaseLink VARCHAR(${releaseLinkMaxLen}) NOT NULL,
adOnly TINYINT(1) NOT NULL DEFAULT 0,
channelId VARCHAR(64) NOT NULL
)`;
const apworldAliases = `CREATE TABLE IF NOT EXISTS apworld_aliases (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
worldId BIGINT NOT NULL,
alias VARCHAR(${worldNameMaxLen}) NOT NULL
)`;
// From ArchipelaBot, probably will be removed eventually
const readySystems = `CREATE TABLE IF NOT EXISTS ready_systems (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guildDataId BIGINT NOT NULL,
channelId VARCHAR(64) NOT NULL,
userId VARCHAR(64) NOT NULL,
UNIQUE (guildDataId, channelId)
)`;
const readyChecks = `CREATE TABLE IF NOT EXISTS ready_checks (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
readySystemId BIGINT NOT NULL,
userId VARCHAR(64) NOT NULL,
isReady TINYINT(1) NOT NULL DEFAULT 0,
UNIQUE (readySystemId, userId)
)`;
const db = mysql.createConnection({
host: config.dbHost,
user: config.dbUser,
password: config.dbPass,
database: config.dbName,
supportBigNumbers: true,
bigNumberStrings: true,
});
const handler = (err) => console.log(err);
db.query(guildData, handler);
db.query(roleSystems, handler);
db.query(roleCategories, handler);
db.query(roles, handler);
db.query(roomSystems, handler);
db.query(roomSystemChannels, handler);
db.query(scheduledEvents, handler);
db.query(eventRspv, handler);
db.query(modContact, handler);
db.query(modContactChannels, handler);
db.query(messageTags, handler);
db.query(tagAliases, handler);
db.query(guildOptions, handler);
db.query(pingableRoles, handler);
db.query(threadManagement, handler);
db.query(alertedThreads, handler);
db.query(pinnedForumPosts, handler);
db.query(scheduleBoards, handler);
db.query(apworldInfo, handler);
db.query(apworldAliases, handler);
db.query(readySystems, handler);
db.query(readyChecks, handler);
db.end();