1
1
mirror of https://github.com/Burn-E99/TheArtificer.git synced 2026-01-06 20:37:54 -05:00

update db structure to let init work correctly

This commit is contained in:
Ean Milligan
2025-04-26 13:22:45 -04:00
parent ef08cd779a
commit 76e007e2e4
44 changed files with 2543 additions and 2280 deletions

View File

@ -2,10 +2,11 @@
// DATA WILL BE LOST IF DB ALREADY EXISTS, RUN AT OWN RISK
import config from '../config.ts';
import { dbClient } from '../src/db.ts';
import dbClient from '../src/db/client.ts';
console.log('Attempting to create DB');
await dbClient.execute(`CREATE SCHEMA IF NOT EXISTS ${config.db.name};`);
console.log('test');
await dbClient.execute(`USE ${config.db.name}`);
console.log('DB created');

View File

@ -1,28 +1,47 @@
// This file will populate the tables with default values
import config from '../config.ts';
import { dbClient } from '../src/db.ts';
import dbClient from '../src/db/client.ts';
console.log('Attempting to populate DB Admin API key');
await dbClient.execute('INSERT INTO all_keys(userid,apiKey) values(?,?)', [config.api.admin, config.api.adminKey]).catch((e) => {
console.log('Failed to insert into database', e);
console.log('Failed to insert into database', e);
});
console.log('Inesrtion done');
console.log('Attempting to insert default commands into command_cnt');
const commands = ['ping', 'rip', 'rollhelp', 'help', 'info', 'version', 'report', 'stats', 'roll', 'emojis', 'api', 'privacy', 'mention', 'audit', 'heatmap', 'rollDecorators', 'opt-out', 'opt-in'];
const commands = [
'ping',
'rip',
'rollhelp',
'help',
'info',
'version',
'report',
'stats',
'roll',
'emojis',
'api',
'privacy',
'mention',
'audit',
'heatmap',
'rollDecorators',
'opt-out',
'opt-in',
];
for (const command of commands) {
await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [command]).catch((e) => {
console.log(`Failed to insert ${command} into database`, e);
});
await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [command]).catch((e) => {
console.log(`Failed to insert ${command} into database`, e);
});
}
console.log('Insertion done');
console.log('Attempting to insert default hours into roll_time_heatmap');
for (let i = 0; i <= 23; i++) {
await dbClient.execute('INSERT INTO roll_time_heatmap(hour) values(?)', [i]).catch((e) => {
console.log(`Failed to insert hour ${i} into database`, e);
});
await dbClient.execute('INSERT INTO roll_time_heatmap(hour) values(?)', [i]).catch((e) => {
console.log(`Failed to insert hour ${i} into database`, e);
});
}
console.log('Insertion done');