Add migration script and update remove and adduser functions.

Needs a UI, API, and functionality.
merge-requests/25/head
knotteye 2020-10-10 16:35:05 -05:00
parent 7b25a7bc97
commit 5fe4728c11
2 changed files with 12 additions and 0 deletions

View File

@ -22,6 +22,7 @@ async function addUser(name: string, password: string){
await query('INSERT INTO users (username, password_hash, stream_key, record_flag) VALUES ('+raw.escape(name)+', '+raw.escape(hash)+', '+raw.escape(key)+', 0)');
await query('INSERT INTO user_meta (username, title, about, live) VALUES ('+raw.escape(name)+',\'\',\'\',false)');
await query('INSERT INTO chat_integration (username, irc, xmpp, twitch, discord) VALUES ('+raw.escape(name)+',\'\',\'\',\'\',\'\')');
await query('INSERT INTO twitch_mirror (username) VALUES ('+raw.escape(name)+')');
return true;
}
@ -30,6 +31,8 @@ async function rmUser(name: string){
if(!exist[0]) return false;
await query('delete from users where username='+raw.escape(name)+' limit 1');
await query('delete from user_meta where username='+raw.escape(name)+' limit 1');
await query('delete from chat_integration where username='+raw.escape(name)+' limit 1');
await query('delete from twitch_mirror where username='+raw.escape(name)+' limit 1');
return true;
}

9
src/db/1.ts Normal file
View File

@ -0,0 +1,9 @@
import * as db from "../database";
async function run () {
await db.query('CREATE TABLE IF NOT EXISTS twitch_mirror(username VARCHAR(25), enabled TINYINT DEFAULT 0, twitch_key VARCHAR(50) DEFAULT \"\")');
await db.query('INSERT INTO twitch_mirror(username) SELECT username FROM users');
await db.query('INSERT INTO db_meta (version) VALUES (1)');
}
export { run }