]> git.r.bdr.sh - rbdr/lgtm/commitdiff
Add DB setup script
authorBen Beltran <redacted>
Mon, 28 Nov 2016 08:26:57 +0000 (02:26 -0600)
committerBen Beltran <redacted>
Mon, 28 Nov 2016 08:26:57 +0000 (02:26 -0600)
scripts/setup_database.js [new file with mode: 0644]

diff --git a/scripts/setup_database.js b/scripts/setup_database.js
new file mode 100644 (file)
index 0000000..554f8d1
--- /dev/null
@@ -0,0 +1,46 @@
+'use strict';
+
+const Config = require('../config/config');
+const Mysql = require('mysql2');
+
+const internals = {};
+
+internals.run = () => {
+
+  console.log('        .');
+  console.log('       /');
+  console.log('    +-----+');
+  console.log('    | o o |  - Loading Good Things Momentarily');
+  console.log('    +-----+');
+  console.log('  +---------+');
+  console.log(' /|    [][] |\\');
+  console.log(' ||         | |');
+  console.log(' ||         |  \\c');
+  console.log(' ^+---------+');
+  console.log('      (.) ');
+
+  const connection = Mysql.createConnection(Config.mysql);
+
+  console.log(`> *BEEP* CREATING TABLE: ${Config.mysql.tableName}!`);
+  connection.query(`CREATE TABLE ${Config.mysql.tableName} (` +
+                    'id SERIAL, ' +
+                    'l VARCHAR(255), ' +
+                    'g VARCHAR(255), ' +
+                    't VARCHAR(255), ' +
+                    'm VARCHAR(255), ' +
+                    'emoji VARCHAR(255), ' +
+                    'PRIMARY KEY (id) ' +
+                    ') CHARACTER SET utf8mb4', (err) => {
+
+    if (err) {
+      console.error(`> *BWOOOP* ERROR DETECTED: ${err.message}!`);
+      process.exit(1);
+    }
+
+    console.log('> *BEEP BEEP* SUCCESS!');
+    process.exit(0);
+  });
+};
+
+internals.run();
+