From: Ben Beltran Date: Mon, 28 Nov 2016 08:26:57 +0000 (-0600) Subject: Add DB setup script X-Git-Url: https://git.r.bdr.sh/rbdr/lgtm/commitdiff_plain/f5efb2b5de23844e6317a6f636abb75955e60c40?ds=sidebyside Add DB setup script --- diff --git a/scripts/setup_database.js b/scripts/setup_database.js new file mode 100644 index 0000000..554f8d1 --- /dev/null +++ b/scripts/setup_database.js @@ -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(); +