From 56e4f63ffaad8c9cb0ffc23a47c1fe5f2891864f Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Sun, 16 Jul 2023 20:44:22 -0600 Subject: [PATCH] feat: improve MySQL database creation --- backend/sql/mysql.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/sql/mysql.ts b/backend/sql/mysql.ts index fe975a0..270780c 100644 --- a/backend/sql/mysql.ts +++ b/backend/sql/mysql.ts @@ -10,11 +10,11 @@ export class MySql { /** * Quick function for creating a simple JSON table */ - private static _tableManager(mode: 'create' | 'drop', name: string): Promise { + private static _tableManager(mode: 'create' | 'drop', name: string, schema = '( NanoID varchar(255), Data JSON )'): Promise { return new Promise((resolve, reject) => MySql._pool.query( mode === 'create' - ? `CREATE TABLE ${name} ( NanoID varchar(255), Data JSON );` + ? `CREATE TABLE ${name} ${schema};` : `DROP TABLE ${name};`) .then(() => resolve()) .catch((err) => reject(err))); @@ -42,7 +42,11 @@ export class MySql { // Create tables if needed if (rows_tableData.length === 0) { log.warn('MySQL', 'Tables do not exist, creating'); - await Promise.all([MySql._tableManager('create', 'assfiles'), MySql._tableManager('create', 'assusers')]); + await Promise.all([ + MySql._tableManager('create', 'assfiles'), + MySql._tableManager('create', 'assusers'), + MySql._tableManager('create', 'asstokens') + ]); log.success('MySQL', 'Tables created').callback(resolve); } else {