浏览代码

Rework database structure

Markus-Rost 4 年之前
父节点
当前提交
883109a78f
共有 12 个文件被更改,包括 222 次插入175 次删除
  1. 1 15
      bot.js
  2. 1 17
      cmds/eval.js
  3. 1 1
      cmds/patreon.js
  4. 3 1
      cmds/rcscript.js
  5. 11 9
      cmds/settings.js
  6. 2 0
      cmds/verification.js
  7. 1 1
      cmds/voice.js
  8. 1 1
      dashboard/settings.js
  9. 7 2
      dashboard/util.js
  10. 173 0
      database.js
  11. 10 2
      main.js
  12. 11 126
      util/database.js

+ 1 - 15
bot.js

@@ -280,7 +280,7 @@ client.on( 'guildDelete', guild => {
 		return;
 		return;
 	}
 	}
 	console.log( '- I\'ve been removed from a server.' );
 	console.log( '- I\'ve been removed from a server.' );
-	db.run( 'DELETE FROM discord WHERE guild = ?', [guild.id], function (dberror) {
+	db.run( 'DELETE FROM discord WHERE main = ?', [guild.id], function (dberror) {
 		if ( dberror ) {
 		if ( dberror ) {
 			console.log( '- Error while removing the settings: ' + dberror );
 			console.log( '- Error while removing the settings: ' + dberror );
 			return dberror;
 			return dberror;
@@ -289,20 +289,6 @@ client.on( 'guildDelete', guild => {
 		if ( guild.id in voice ) delete voice[guild.id];
 		if ( guild.id in voice ) delete voice[guild.id];
 		if ( this.changes ) console.log( '- Settings successfully removed.' );
 		if ( this.changes ) console.log( '- Settings successfully removed.' );
 	} );
 	} );
-	db.run( 'DELETE FROM verification WHERE guild = ?', [guild.id], function (dberror) {
-		if ( dberror ) {
-			console.log( '- Error while removing the verifications: ' + dberror );
-			return dberror;
-		}
-		if ( this.changes ) console.log( '- Verifications successfully removed.' );
-	} );
-	db.run( 'DELETE FROM rcgcdw WHERE guild = ?', [guild.id], function (dberror) {
-		if ( dberror ) {
-			console.log( '- Error while removing the RcGcDw: ' + dberror );
-			return dberror;
-		}
-		if ( this.changes ) console.log( '- RcGcDw successfully removed.' );
-	} );
 } );
 } );
 
 
 
 

+ 1 - 17
cmds/eval.js

@@ -289,7 +289,7 @@ function removeSettings(msg) {
 					return error;
 					return error;
 				}
 				}
 				if ( guilds.length ) {
 				if ( guilds.length ) {
-					db.run( 'DELETE FROM discord WHERE guild IN (' + guilds.map( guild => '?' ).join(', ') + ')', guilds, function (dberror) {
+					db.run( 'DELETE FROM discord WHERE main IN (' + guilds.map( guild => '?' ).join(', ') + ')', guilds, function (dberror) {
 						if ( dberror ) {
 						if ( dberror ) {
 							console.log( '- Error while removing the guilds: ' + dberror );
 							console.log( '- Error while removing the guilds: ' + dberror );
 							msg.replyMsg( 'I got an error while removing the guilds!', {}, true );
 							msg.replyMsg( 'I got an error while removing the guilds!', {}, true );
@@ -297,22 +297,6 @@ function removeSettings(msg) {
 						}
 						}
 						console.log( '- Guilds successfully removed.' );
 						console.log( '- Guilds successfully removed.' );
 					} );
 					} );
-					db.run( 'DELETE FROM verification WHERE guild IN (' + guilds.map( guild => '?' ).join(', ') + ')', guilds, function (dberror) {
-						if ( dberror ) {
-							console.log( '- Error while removing the verifications: ' + dberror );
-							msg.replyMsg( 'I got an error while removing the verifications!', {}, true );
-							return dberror;
-						}
-						console.log( '- Verifications successfully removed.' );
-					} );
-					db.run( 'DELETE FROM rcgcdw WHERE guild IN (' + guilds.map( guild => '?' ).join(', ') + ')', guilds, function (dberror) {
-						if ( dberror ) {
-							console.log( '- Error while removing the RcGcDw: ' + dberror );
-							msg.replyMsg( 'I got an error while removing the RcGcDw!', {}, true );
-							return dberror;
-						}
-						console.log( '- Verifications successfully removed.' );
-					} );
 				}
 				}
 				if ( channels.length ) db.run( 'DELETE FROM discord WHERE channel IN (' + channels.map( channel => '?' ).join(', ') + ')', channels, function (dberror) {
 				if ( channels.length ) db.run( 'DELETE FROM discord WHERE channel IN (' + channels.map( channel => '?' ).join(', ') + ')', channels, function (dberror) {
 					if ( dberror ) {
 					if ( dberror ) {

+ 1 - 1
cmds/patreon.js

@@ -39,7 +39,7 @@ function cmd_patreon(lang, msg, args, line, wiki) {
 					msg.replyMsg( 'I got an error while updating the server, please try again later.', {}, true );
 					msg.replyMsg( 'I got an error while updating the server, please try again later.', {}, true );
 					return error;
 					return error;
 				}
 				}
-				if ( !this.changes ) return db.run( 'INSERT INTO discord(guild, patreon) VALUES(?, ?)', [args[1], msg.author.id], function (inserror) {
+				if ( !this.changes ) return db.run( 'INSERT INTO discord(main, guild, patreon) VALUES(?, ?, ?)', [args[1], args[1], msg.author.id], function (inserror) {
 					if ( inserror ) {
 					if ( inserror ) {
 						console.log( '- Error while adding the guild: ' + inserror );
 						console.log( '- Error while adding the guild: ' + inserror );
 						msg.replyMsg( 'I got an error while updating the server, please try again later.', {}, true );
 						msg.replyMsg( 'I got an error while updating the server, please try again later.', {}, true );

+ 3 - 1
cmds/rcscript.js

@@ -1,5 +1,6 @@
 const cheerio = require('cheerio');
 const cheerio = require('cheerio');
-const {limit: {rcgcdw: rcgcdwLimit}, defaultSettings, wikiProjects} = require('../util/default.json');
+const help_setup = require('../functions/helpsetup.js');
+const {limit: {rcgcdw: rcgcdwLimit}, defaultSettings} = require('../util/default.json');
 const Lang = require('../util/i18n.js');
 const Lang = require('../util/i18n.js');
 const allLangs = Lang.allLangs(true);
 const allLangs = Lang.allLangs(true);
 const Wiki = require('../util/wiki.js');
 const Wiki = require('../util/wiki.js');
@@ -26,6 +27,7 @@ const display_types = [
 function cmd_rcscript(lang, msg, args, line, wiki) {
 function cmd_rcscript(lang, msg, args, line, wiki) {
 	if ( args[0] === 'block' && msg.isOwner() ) return blocklist(msg, args.slice(1));
 	if ( args[0] === 'block' && msg.isOwner() ) return blocklist(msg, args.slice(1));
 	if ( !msg.isAdmin() ) return msg.reactEmoji('❌');
 	if ( !msg.isAdmin() ) return msg.reactEmoji('❌');
+	if ( msg.defaultSettings ) return help_setup(lang, msg);
 	
 	
 	db.all( 'SELECT configid, webhook, wiki, lang, display, wikiid, rcid FROM rcgcdw WHERE guild = ? ORDER BY configid ASC', [msg.guild.id], (dberror, rows) => {
 	db.all( 'SELECT configid, webhook, wiki, lang, display, wikiid, rcid FROM rcgcdw WHERE guild = ? ORDER BY configid ASC', [msg.guild.id], (dberror, rows) => {
 		if ( dberror || !rows ) {
 		if ( dberror || !rows ) {

+ 11 - 9
cmds/settings.js

@@ -162,10 +162,10 @@ function cmd_settings(lang, msg, args, line, wiki) {
 					var sql = 'UPDATE discord SET wiki = ? WHERE guild = ? AND wiki = ?';
 					var sql = 'UPDATE discord SET wiki = ? WHERE guild = ? AND wiki = ?';
 					var sqlargs = [wikinew.href, msg.guild.id, guild.wiki];
 					var sqlargs = [wikinew.href, msg.guild.id, guild.wiki];
 					if ( !rows.length ) {
 					if ( !rows.length ) {
-						sql = 'INSERT INTO discord(wiki, guild) VALUES(?, ?)';
-						sqlargs.pop();
+						sql = 'INSERT INTO discord(wiki, guild, main) VALUES(?, ?, ?)';
+						sqlargs[2] = msg.guild.id;
 					}
 					}
-					if ( channel ) {
+					else if ( channel ) {
 						sql = 'UPDATE discord SET wiki = ? WHERE guild = ? AND channel = ?';
 						sql = 'UPDATE discord SET wiki = ? WHERE guild = ? AND channel = ?';
 						sqlargs[2] = msg.channel.id;
 						sqlargs[2] = msg.channel.id;
 						if ( !rows.includes( channel ) ) {
 						if ( !rows.includes( channel ) ) {
@@ -227,10 +227,10 @@ function cmd_settings(lang, msg, args, line, wiki) {
 			var sql = 'UPDATE discord SET lang = ? WHERE guild = ? AND lang = ?';
 			var sql = 'UPDATE discord SET lang = ? WHERE guild = ? AND lang = ?';
 			var sqlargs = [allLangs.map[args[1]], msg.guild.id, guild.lang];
 			var sqlargs = [allLangs.map[args[1]], msg.guild.id, guild.lang];
 			if ( !rows.length ) {
 			if ( !rows.length ) {
-				sql = 'INSERT INTO discord(lang, guild) VALUES(?, ?)';
-				sqlargs.pop();
+				sql = 'INSERT INTO discord(lang, guild, main) VALUES(?, ?, ?)';
+				sqlargs[2] = msg.guild.id;
 			}
 			}
-			if ( channel ) {
+			else if ( channel ) {
 				sql = 'UPDATE discord SET lang = ? WHERE guild = ? AND channel = ?';
 				sql = 'UPDATE discord SET lang = ? WHERE guild = ? AND channel = ?';
 				sqlargs[2] = msg.channel.id;
 				sqlargs[2] = msg.channel.id;
 				if ( !rows.includes( channel ) ) {
 				if ( !rows.includes( channel ) ) {
@@ -286,7 +286,8 @@ function cmd_settings(lang, msg, args, line, wiki) {
 			var sql = 'UPDATE discord SET prefix = ? WHERE guild = ?';
 			var sql = 'UPDATE discord SET prefix = ? WHERE guild = ?';
 			var sqlargs = [args[1], msg.guild.id];
 			var sqlargs = [args[1], msg.guild.id];
 			if ( !rows.length ) {
 			if ( !rows.length ) {
-				sql = 'INSERT INTO discord(prefix, guild) VALUES(?, ?)';
+				sql = 'INSERT INTO discord(prefix, guild, main) VALUES(?, ?, ?)';
+				sqlargs.push(msg.guild.id);
 			}
 			}
 			return db.run( sql, sqlargs, function (dberror) {
 			return db.run( sql, sqlargs, function (dberror) {
 				if ( dberror ) {
 				if ( dberror ) {
@@ -314,9 +315,10 @@ function cmd_settings(lang, msg, args, line, wiki) {
 			var sql = 'UPDATE discord SET inline = ? WHERE guild = ?';
 			var sql = 'UPDATE discord SET inline = ? WHERE guild = ?';
 			var sqlargs = [value, msg.guild.id];
 			var sqlargs = [value, msg.guild.id];
 			if ( !rows.length ) {
 			if ( !rows.length ) {
-				sql = 'INSERT INTO discord(inline, guild) VALUES(?, ?)';
+				sql = 'INSERT INTO discord(inline, guild, main) VALUES(?, ?, ?)';
+				sqlargs.push(msg.guild.id);
 			}
 			}
-			if ( channel ) {
+			else if ( channel ) {
 				sql = 'UPDATE discord SET inline = ? WHERE guild = ? AND channel = ?';
 				sql = 'UPDATE discord SET inline = ? WHERE guild = ? AND channel = ?';
 				sqlargs.push(msg.channel.id);
 				sqlargs.push(msg.channel.id);
 				if ( !rows.includes( channel ) ) {
 				if ( !rows.includes( channel ) ) {

+ 2 - 0
cmds/verification.js

@@ -1,3 +1,4 @@
+const help_setup = require('../functions/helpsetup.js');
 const {limit: {verification: verificationLimit}} = require('../util/default.json');
 const {limit: {verification: verificationLimit}} = require('../util/default.json');
 var db = require('../util/database.js');
 var db = require('../util/database.js');
 
 
@@ -15,6 +16,7 @@ function cmd_verification(lang, msg, args, line, wiki) {
 		else msg.reactEmoji('❌');
 		else msg.reactEmoji('❌');
 		return;
 		return;
 	}
 	}
+	if ( msg.defaultSettings ) return help_setup(lang, msg);
 	if ( !msg.guild.me.permissions.has('MANAGE_ROLES') ) {
 	if ( !msg.guild.me.permissions.has('MANAGE_ROLES') ) {
 		console.log( msg.guild.id + ': Missing permissions - MANAGE_ROLES' );
 		console.log( msg.guild.id + ': Missing permissions - MANAGE_ROLES' );
 		return msg.replyMsg( lang.get('general.missingperm') + ' `MANAGE_ROLES`' );
 		return msg.replyMsg( lang.get('general.missingperm') + ' `MANAGE_ROLES`' );

+ 1 - 1
cmds/voice.js

@@ -26,7 +26,7 @@ function cmd_voice(lang, msg, args, line, wiki) {
 					msg.replyMsg( lang.get('settings.save_failed'), {}, true );
 					msg.replyMsg( lang.get('settings.save_failed'), {}, true );
 					return dberror;
 					return dberror;
 				}
 				}
-				if ( !this.changes ) return db.run( 'INSERT INTO discord(guild, voice) VALUES(?, ?)', [msg.guild.id, value], function (error) {
+				if ( !this.changes ) return db.run( 'INSERT INTO discord(main, guild, voice) VALUES(?, ?, ?)', [msg.guild.id, msg.guild.id, value], function (error) {
 					if ( error ) {
 					if ( error ) {
 						console.log( '- Error while adding the voice settings: ' + error );
 						console.log( '- Error while adding the voice settings: ' + error );
 						msg.replyMsg( lang.get('settings.save_failed'), {}, true );
 						msg.replyMsg( lang.get('settings.save_failed'), {}, true );

+ 1 - 1
dashboard/settings.js

@@ -326,7 +326,7 @@ function update_settings(res, userSettings, guild, type, settings) {
 					settings.prefix = settings.prefix.trim().toLowerCase();
 					settings.prefix = settings.prefix.trim().toLowerCase();
 					if ( settings.prefix_space ) settings.prefix += ' ';
 					if ( settings.prefix_space ) settings.prefix += ' ';
 				}
 				}
-				if ( !row ) return db.run( 'INSERT INTO discord(wiki, lang, inline, prefix, guild) VALUES(?, ?, ?, ?, ?)', [wiki.href, settings.lang, ( settings.inline ? null : 1 ), ( settings.prefix || process.env.prefix ), guild], function(dberror) {
+				if ( !row ) return db.run( 'INSERT INTO discord(wiki, lang, inline, prefix, guild, main) VALUES(?, ?, ?, ?, ?, ?)', [wiki.href, settings.lang, ( settings.inline ? null : 1 ), ( settings.prefix || process.env.prefix ), guild, guild], function(dberror) {
 					if ( dberror ) {
 					if ( dberror ) {
 						console.log( '- Dashboard: Error while saving the settings: ' + dberror );
 						console.log( '- Dashboard: Error while saving the settings: ' + dberror );
 						return res(`/guild/${guild}/settings?save=failed`);
 						return res(`/guild/${guild}/settings?save=failed`);

+ 7 - 2
dashboard/util.js

@@ -5,13 +5,18 @@ const got = require('got').extend( {
 	responseType: 'json'
 	responseType: 'json'
 } );
 } );
 const sqlite3 = require('sqlite3').verbose();
 const sqlite3 = require('sqlite3').verbose();
-const mode = ( process.env.READONLY ? sqlite3.OPEN_READONLY : sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE );
+const mode = ( process.env.READONLY ? sqlite3.OPEN_READONLY : sqlite3.OPEN_READWRITE );
 const db = new sqlite3.Database( './wikibot.db', mode, dberror => {
 const db = new sqlite3.Database( './wikibot.db', mode, dberror => {
 	if ( dberror ) {
 	if ( dberror ) {
 		console.log( '- Dashboard: Error while connecting to the database: ' + dberror );
 		console.log( '- Dashboard: Error while connecting to the database: ' + dberror );
 		return dberror;
 		return dberror;
 	}
 	}
-	console.log( '- Dashboard: Connected to the database.' );
+	db.exec( 'PRAGMA foreign_keys = ON;', function (error) {
+		if ( error ) {
+			console.log( '- Dashboard: Error while enabling the foreign key constraint: ' + error );
+		}
+		console.log( '- Dashboard: Connected to the database.' );
+	} );
 } );
 } );
 
 
 /**
 /**

+ 173 - 0
database.js

@@ -0,0 +1,173 @@
+const {defaultSettings} = require('./util/default.json');
+const sqlite3 = require('sqlite3').verbose();
+const mode = ( process.env.READONLY ? sqlite3.OPEN_READONLY : sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE );
+
+const schema = [`
+BEGIN TRANSACTION;
+
+CREATE TABLE patreons (
+    patreon TEXT    PRIMARY KEY
+                    UNIQUE
+                    NOT NULL,
+    count   INTEGER NOT NULL
+);
+
+CREATE INDEX idx_patreons_patreon ON patreons (
+    patreon
+);
+
+CREATE TABLE discord (
+    guild   TEXT    NOT NULL
+                    REFERENCES discord (main) ON DELETE CASCADE,
+    channel TEXT,
+    lang    TEXT    NOT NULL
+                    DEFAULT [${defaultSettings.lang}],
+    wiki    TEXT    NOT NULL
+                    DEFAULT [${defaultSettings.wiki}],
+    prefix  TEXT    NOT NULL
+                    DEFAULT [${process.env.prefix}],
+    patreon TEXT    REFERENCES patreons (patreon) ON DELETE SET NULL,
+    voice   INTEGER,
+    inline  INTEGER,
+    main    TEXT    UNIQUE
+                    CHECK (main = guild),
+    UNIQUE (
+        guild,
+        channel
+    )
+);
+
+CREATE INDEX idx_discord_channel ON discord (
+    guild,
+    channel DESC
+);
+
+CREATE INDEX idx_discord_patreon ON discord (
+    patreon
+)
+WHERE patreon IS NOT NULL;
+
+CREATE INDEX idx_discord_voice ON discord (
+    voice
+)
+WHERE voice IS NOT NULL;
+
+CREATE TABLE verification (
+    guild      TEXT    NOT NULL
+                       REFERENCES discord (main) ON DELETE CASCADE,
+    configid   INTEGER NOT NULL,
+    channel    TEXT    NOT NULL,
+    role       TEXT    NOT NULL,
+    editcount  INTEGER NOT NULL
+                       DEFAULT [0],
+    usergroup  TEXT    NOT NULL
+                       DEFAULT [user],
+    accountage INTEGER NOT NULL
+                       DEFAULT [0],
+    rename     INTEGER NOT NULL
+                       DEFAULT [0],
+    UNIQUE (
+        guild,
+        configid
+    )
+);
+
+CREATE INDEX idx_verification_config ON verification (
+    guild,
+    configid ASC,
+    channel
+);
+
+CREATE TABLE rcgcdw (
+    guild    TEXT    NOT NULL
+                     REFERENCES discord (main) ON DELETE CASCADE,
+    configid INTEGER NOT NULL,
+    webhook  TEXT    NOT NULL
+                     UNIQUE,
+    wiki     TEXT    NOT NULL,
+    lang     TEXT    NOT NULL
+                     DEFAULT [${defaultSettings.lang}],
+    display  INTEGER NOT NULL
+                     DEFAULT [1],
+    wikiid   INTEGER,
+    rcid     INTEGER,
+    postid   TEXT,
+    UNIQUE (
+        guild,
+        configid
+    )
+);
+
+CREATE INDEX idx_rcgcdw_wiki ON rcgcdw (
+    wiki
+);
+
+CREATE INDEX idx_rcgcdw_webhook ON rcgcdw (
+    webhook
+);
+
+CREATE INDEX idx_rcgcdw_config ON rcgcdw (
+    guild,
+    configid ASC
+);
+
+CREATE TABLE blocklist (
+    wiki   TEXT UNIQUE
+                NOT NULL,
+    reason TEXT
+);
+
+CREATE INDEX idx_blocklist_wiki ON blocklist (
+    wiki
+);
+
+COMMIT TRANSACTION;
+PRAGMA user_version = 1;
+`];
+
+module.exports = new Promise( (resolve, reject) => {
+	const db = new sqlite3.Database( './wikibot.db', mode, dberror => {
+		if ( dberror ) {
+			console.log( '- Error while connecting to the database: ' + dberror );
+			return reject();
+		}
+		db.get( 'PRAGMA user_version;', (error, row) => {
+			if ( error ) {
+				console.log( '- Error while getting the database version: ' + error );
+				return reject();
+			}
+			if ( row.user_version > schema.length ) {
+				console.log( '- Invalid database version: ' + row.user_version );
+				return reject();
+			}
+			if ( row.user_version === schema.length ) {
+				console.log( '- The database is up to date: ' + row.user_version );
+				db.close( cerror => {
+					if ( cerror ) {
+						console.log( '- Error while closing the database connection: ' + cerror );
+						return cerror;
+					}
+				} );
+				return resolve();
+			}
+			console.log( '- The database outdated: ' + row.user_version );
+			if ( process.env.READONLY ) return reject();
+			db.exec( schema.filter( (sql, version) => {
+				return ( row.user_version > version );
+			} ).join('\n'), exerror => {
+				if ( exerror ) {
+					console.log( '- Error while updating the database: ' + exerror );
+					return reject();
+				}
+				console.log( '- The database has been updated to: ' + schema.length );
+				db.close( cerror => {
+					if ( cerror ) {
+						console.log( '- Error while closing the database connection: ' + cerror );
+						return cerror;
+					}
+				} );
+				return resolve();
+			} );
+		} );
+	} );
+} );

+ 10 - 2
main.js

@@ -1,8 +1,12 @@
 require('dotenv').config();
 require('dotenv').config();
-const child_process = require('child_process');
 
 
 const isDebug = ( process.argv[2] === 'debug' );
 const isDebug = ( process.argv[2] === 'debug' );
 if ( process.argv[2] === 'readonly' ) process.env.READONLY = true;
 if ( process.argv[2] === 'readonly' ) process.env.READONLY = true;
+
+require('./database.js').then( () => {
+
+const child_process = require('child_process');
+
 const got = require('got').extend( {
 const got = require('got').extend( {
 	throwHttpErrors: false,
 	throwHttpErrors: false,
 	timeout: 30000,
 	timeout: 30000,
@@ -240,4 +244,8 @@ if ( isDebug && process.argv[3]?.startsWith( '--timeout:' ) ) {
 		manager.shards.forEach( shard => shard.kill() );
 		manager.shards.forEach( shard => shard.kill() );
 		if ( typeof server !== 'undefined' ) server.kill();
 		if ( typeof server !== 'undefined' ) server.kill();
 	}, timeout * 1000 ).unref();
 	}, timeout * 1000 ).unref();
-}
+}
+
+}, () => {
+	process.exit(1);
+} )

+ 11 - 126
util/database.js

@@ -1,13 +1,18 @@
 const {defaultSettings} = require('../util/default.json');
 const {defaultSettings} = require('../util/default.json');
 const sqlite3 = require('sqlite3').verbose();
 const sqlite3 = require('sqlite3').verbose();
-const mode = ( process.env.READONLY ? sqlite3.OPEN_READONLY : sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE );
+const mode = ( process.env.READONLY ? sqlite3.OPEN_READONLY : sqlite3.OPEN_READWRITE );
 const db = new sqlite3.Database( './wikibot.db', mode, dberror => {
 const db = new sqlite3.Database( './wikibot.db', mode, dberror => {
 	if ( dberror ) {
 	if ( dberror ) {
 		console.log( '- ' + shardId + ': Error while connecting to the database: ' + dberror );
 		console.log( '- ' + shardId + ': Error while connecting to the database: ' + dberror );
 		return dberror;
 		return dberror;
 	}
 	}
-	console.log( '- ' + shardId + ': Connected to the database.' );
-	getSettings();
+	db.exec( 'PRAGMA foreign_keys = ON;', function (error) {
+		if ( error ) {
+			console.log( '- ' + shardId + ': Error while enabling the foreign key constraint: ' + error );
+		}
+		console.log( '- ' + shardId + ': Connected to the database.' );
+		getSettings();
+	} );
 } );
 } );
 
 
 /**
 /**
@@ -28,132 +33,12 @@ function getSettings(trysettings = 1) {
 	}, (dberror) => {
 	}, (dberror) => {
 		if ( dberror ) {
 		if ( dberror ) {
 			console.log( '- ' + trysettings + '. Error while getting the patreons: ' + dberror );
 			console.log( '- ' + trysettings + '. Error while getting the patreons: ' + dberror );
-			if ( dberror.message === 'SQLITE_ERROR: no such table: discord' ) db.serialize( () => {
-				db.run( 'CREATE TABLE IF NOT EXISTS patreons(patreon TEXT PRIMARY KEY UNIQUE NOT NULL, count INTEGER NOT NULL)', [], function (error) {
-					if ( error ) {
-						console.log( '- ' + shardId + ': Error while creating the patreons table: ' + error );
-						return error;
-					}
-					console.log( '- ' + shardId + ': Created the patreons table.' );
-					db.run( 'CREATE INDEX idx_patreons_patreon ON patreons(patreon)', [], function (idxerror) {
-						if ( idxerror ) {
-							console.log( '- ' + shardId + ': Error while creating the patreons index: ' + idxerror );
-							return idxerror;
-						}
-						console.log( '- ' + shardId + ': Created the patreons index.' );
-					} );
-				} );
-				db.run( 'CREATE TABLE IF NOT EXISTS discord(guild TEXT NOT NULL, channel TEXT, lang TEXT NOT NULL DEFAULT [' + defaultSettings.lang + '], wiki TEXT NOT NULL DEFAULT [' + defaultSettings.wiki + '], prefix TEXT NOT NULL DEFAULT [' + process.env.prefix + '], patreon TEXT, voice INTEGER, inline INTEGER, UNIQUE(guild, channel), FOREIGN KEY(patreon) REFERENCES patreons(patreon) ON DELETE SET NULL)', [], function (error) {
-					if ( error ) {
-						console.log( '- ' + shardId + ': Error while creating the discord table: ' + error );
-						return error;
-					}
-					console.log( '- ' + shardId + ': Created the discord table.' );
-					db.run( 'CREATE TRIGGER unique_discord_guild BEFORE INSERT ON discord WHEN NEW.channel IS NULL BEGIN SELECT CASE WHEN (SELECT 1 FROM discord WHERE guild = NEW.guild AND channel IS NULL) IS NOT NULL THEN RAISE(ABORT, "UNIQUE constraint failed: discord.guild, discord.channel") END; END;', [], function (tgerror) {
-						if ( tgerror ) {
-							console.log( '- ' + shardId + ': Error while creating the discord guild trigger: ' + tgerror );
-							return tgerror;
-						}
-						console.log( '- ' + shardId + ': Created the discord guild trigger.' );
-					} );
-					db.run( 'CREATE INDEX idx_discord_patreon ON discord(patreon) WHERE patreon IS NOT NULL', [], function (idxerror) {
-						if ( idxerror ) {
-							console.log( '- ' + shardId + ': Error while creating the discord patreon index: ' + idxerror );
-							return idxerror;
-						}
-						console.log( '- ' + shardId + ': Created the discord patreon index.' );
-					} );
-					db.run( 'CREATE INDEX idx_discord_voice ON discord(voice) WHERE voice IS NOT NULL', [], function (idxerror) {
-						if ( idxerror ) {
-							console.log( '- ' + shardId + ': Error while creating the discord voice index: ' + idxerror );
-							return idxerror;
-						}
-						console.log( '- ' + shardId + ': Created the discord voice index.' );
-					} );
-					db.run( 'CREATE INDEX idx_discord_channel ON discord(guild, channel DESC)', [], function (idxerror) {
-						if ( idxerror ) {
-							console.log( '- ' + shardId + ': Error while creating the discord channel index: ' + idxerror );
-							return idxerror;
-						}
-						console.log( '- ' + shardId + ': Created the discord channel index.' );
-					} );
-					if ( trysettings < 10 ) {
-						trysettings++;
-						getSettings(trysettings);
-					}
-				} );
-				db.run( 'CREATE TABLE IF NOT EXISTS verification(guild TEXT NOT NULL, configid INTEGER NOT NULL, channel TEXT NOT NULL, role TEXT NOT NULL, editcount INTEGER NOT NULL DEFAULT [0], usergroup TEXT NOT NULL DEFAULT [user], accountage INTEGER NOT NULL DEFAULT [0], rename INTEGER NOT NULL DEFAULT [0], UNIQUE(guild, configid))', [], function (error) {
-					if ( error ) {
-						console.log( '- ' + shardId + ': Error while creating the verification table: ' + error );
-						return error;
-					}
-					console.log( '- ' + shardId + ': Created the verification table.' );
-					db.run( 'CREATE INDEX idx_verification_config ON verification(guild, configid ASC, channel)', [], function (idxerror) {
-						if ( idxerror ) {
-							console.log( '- ' + shardId + ': Error while creating the verification index: ' + idxerror );
-							return idxerror;
-						}
-						console.log( '- ' + shardId + ': Created the verification index.' );
-					} );
-				} );
-				db.run( 'CREATE TABLE IF NOT EXISTS rcgcdw(guild TEXT NOT NULL, configid INTEGER NOT NULL, webhook TEXT NOT NULL UNIQUE, wiki TEXT NOT NULL, lang TEXT NOT NULL DEFAULT [' + defaultSettings.lang + '], display INTEGER NOT NULL DEFAULT [1], wikiid INTEGER, rcid INTEGER, postid TEXT, UNIQUE(guild, configid))', [], function (error) {
-					if ( error ) {
-						console.log( '- ' + shardId + ': Error while creating the rcgcdw table: ' + error );
-						return error;
-					}
-					console.log( '- ' + shardId + ': Created the rcgcdw table.' );
-					db.run( 'CREATE INDEX idx_rcgcdw_wiki ON rcgcdw(wiki)', [], function (idxerror) {
-						if ( idxerror ) {
-							console.log( '- ' + shardId + ': Error while creating the rcgcdw wiki index: ' + idxerror );
-							return idxerror;
-						}
-						console.log( '- ' + shardId + ': Created the rcgcdw wiki index.' );
-					} );
-					db.run( 'CREATE INDEX idx_rcgcdw_webhook ON rcgcdw(webhook)', [], function (idxerror) {
-						if ( idxerror ) {
-							console.log( '- ' + shardId + ': Error while creating the rcgcdw webhook index: ' + idxerror );
-							return idxerror;
-						}
-						console.log( '- ' + shardId + ': Created the rcgcdw webhook index.' );
-					} );
-					db.run( 'CREATE INDEX idx_rcgcdw_config ON rcgcdw(guild, configid ASC)', [], function (idxerror) {
-						if ( idxerror ) {
-							console.log( '- ' + shardId + ': Error while creating the rcgcdw config index: ' + idxerror );
-							return idxerror;
-						}
-						console.log( '- ' + shardId + ': Created the rcgcdw config index.' );
-					} );
-				} );
-				db.run( 'CREATE TABLE IF NOT EXISTS blocklist(wiki TEXT UNIQUE NOT NULL, reason TEXT)', [], function (error) {
-					if ( error ) {
-						console.log( '- ' + shardId + ': Error while creating the blocklist table: ' + error );
-						return error;
-					}
-					console.log( '- ' + shardId + ': Created the blocklist table.' );
-					db.run( 'CREATE INDEX idx_blocklist_wiki ON blocklist(wiki)', [], function (idxerror) {
-						if ( idxerror ) {
-							console.log( '- ' + shardId + ': Error while creating the blocklist wiki index: ' + idxerror );
-							return idxerror;
-						}
-						console.log( '- ' + shardId + ': Created the blocklist wiki index.' );
-					} );
-				} );
-			} );
-			else {
-				if ( trysettings < 10 ) {
-					trysettings++;
-					getSettings(trysettings);
-				}
+			if ( trysettings < 10 ) {
+				trysettings++;
+				getSettings(trysettings);
 			}
 			}
 			return dberror;
 			return dberror;
 		}
 		}
-		db.run( 'PRAGMA foreign_keys = ON;', [], function (fkerror) {
-			if ( fkerror ) {
-				console.log( '- ' + shardId + ': Error while enabling the foreign key constraint: ' + fkerror );
-				return fkerror;
-			}
-			console.log( '- ' + shardId + ': Enabled the foreign key constraint.' );
-		} );
 		console.log( '- ' + shardId + ': Patreons successfully loaded.' );
 		console.log( '- ' + shardId + ': Patreons successfully loaded.' );
 		getVoice();
 		getVoice();
 	} );
 	} );