From b7acde91ae64afcb9b6a28b1c36422227cfd25e6 Mon Sep 17 00:00:00 2001 From: ToastedToast Date: Sat, 13 Jul 2024 20:09:41 +0800 Subject: [PATCH] chore(db): remove unused columns --- api/db/init.ts | 79 +++++++++++++++++++--------------------- api/db/queries/guilds.ts | 2 - api/index.ts | 9 ++--- 3 files changed, 42 insertions(+), 48 deletions(-) diff --git a/api/db/init.ts b/api/db/init.ts index 895fd53..7ae8380 100644 --- a/api/db/init.ts +++ b/api/db/init.ts @@ -1,18 +1,16 @@ import { pool } from "."; export async function initTables() { - const createGuildsTable = ` + const createGuildsTable = ` CREATE TABLE IF NOT EXISTS guilds ( id VARCHAR(255) NOT NULL PRIMARY KEY, name VARCHAR(255), icon VARCHAR(255), members INT, - cooldown INT DEFAULT 30000, - updates_enabled BOOLEAN DEFAULT FALSE, - updates_channel VARCHAR(255) + cooldown INT DEFAULT 30000 ) `; - const createUsersTable = ` + const createUsersTable = ` CREATE TABLE IF NOT EXISTS users ( id VARCHAR(255) NOT NULL, guild_id VARCHAR(255) NOT NULL, @@ -26,55 +24,54 @@ export async function initTables() { PRIMARY KEY (id, guild_id) ) `; - // FOREIGN KEY (guild_id) REFERENCES guilds(id) - const createRolesTable = ` + // FOREIGN KEY (guild_id) REFERENCES guilds(id) + const createRolesTable = ` CREATE TABLE IF NOT EXISTS roles ( id VARCHAR(255) NOT NULL PRIMARY KEY, guild_id VARCHAR(255) NOT NULL, name VARCHAR(255), level INT NOT NULL ) - ` - // FOREIGN KEY (guild_id) REFERENCES guilds(id) - const createUpdatesTable = ` + `; + // FOREIGN KEY (guild_id) REFERENCES guilds(id) + const createUpdatesTable = ` CREATE TABLE IF NOT EXISTS updates ( guild_id VARCHAR(255) NOT NULL PRIMARY KEY, channel_id VARCHAR(255) NOT NULL, enabled BOOLEAN DEFAULT FALSE ) - ` - // FOREIGN KEY (guild_id) REFERENCES guilds(id) - - pool.query(createGuildsTable, (err) => { - if (err) { - console.error("Error creating guilds table:", err); - } else { - console.log("Guilds table created"); - } - }); + `; + // FOREIGN KEY (guild_id) REFERENCES guilds(id) - pool.query(createUsersTable, (err) => { - if (err) { - console.error("Error creating users table:", err); - } else { - console.log("Users table created"); - } - }); + pool.query(createGuildsTable, (err) => { + if (err) { + console.error("Error creating guilds table:", err); + } else { + console.log("Guilds table created"); + } + }); + pool.query(createUsersTable, (err) => { + if (err) { + console.error("Error creating users table:", err); + } else { + console.log("Users table created"); + } + }); - pool.query(createRolesTable, (err) => { - if (err) { - console.error("Error creating roles table:", err); - } else { - console.log("Roles table created"); - } - }); + pool.query(createRolesTable, (err) => { + if (err) { + console.error("Error creating roles table:", err); + } else { + console.log("Roles table created"); + } + }); - pool.query(createUpdatesTable, (err) => { - if (err) { - console.error("Error creating updates table:", err); - } else { - console.log("Updates table created"); - } - }); + pool.query(createUpdatesTable, (err) => { + if (err) { + console.error("Error creating updates table:", err); + } else { + console.log("Updates table created"); + } + }); } diff --git a/api/db/queries/guilds.ts b/api/db/queries/guilds.ts index d3fc581..297fa00 100644 --- a/api/db/queries/guilds.ts +++ b/api/db/queries/guilds.ts @@ -7,8 +7,6 @@ export interface Guild { icon: string; members: number; cooldown: number; - updates_enabled: boolean; - updates_channel: string; } export async function getGuild(guildId: string): Promise<[QueryError, null] | [null, Guild | null]> { diff --git a/api/index.ts b/api/index.ts index 3062b16..8c7855e 100644 --- a/api/index.ts +++ b/api/index.ts @@ -34,8 +34,7 @@ app.post("/post/:guild", authMiddleware, async (req, res) => { name, icon, members, - updates_enabled: false, - updates_channel: "", + cooldown: 30_000, }); if (err) { @@ -71,10 +70,10 @@ app.post("/post/:guild/:user", authMiddleware, async (req, res) => { ((newXp - currentLevelXp) / (nextLevelXp - currentLevelXp)) * 100; const updateQuery = ` - INSERT INTO users + INSERT INTO users (id, guild_id, xp, pfp, name, nickname, level, xp_needed_next_level, progress_next_level) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) - ON DUPLICATE KEY UPDATE + ON DUPLICATE KEY UPDATE xp = VALUES(xp), pfp = VALUES(pfp), name = VALUES(name), @@ -248,7 +247,7 @@ app.post("/admin/:action/:guild/:target", authMiddleware, async (req, res) => { default: return res.status(500).json({ message: "Internal server error" }); } - case "cooldown": + case "cooldown": if (target !== "set" && target !== "get") { return res.status(400).json({ message: "Illegal request" }); }