From ead516a9d74f346c4556c7eaab7014f95486f29e Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Mon, 28 Nov 2016 02:28:17 -0600 Subject: LGTM-2 Read from database Squashed commit of the following: commit a2a2b553f69a66f1825347abde4f0028773bdbdb Author: Ben Beltran Date: Mon Nov 28 02:27:19 2016 -0600 Fetch random record in record_fetcher commit 6b98202fc8ea9c5811134cad592f11b6b89d008a Author: Ben Beltran Date: Mon Nov 28 02:27:08 2016 -0600 Add some instructions to the readme commit f5efb2b5de23844e6317a6f636abb75955e60c40 Author: Ben Beltran Date: Mon Nov 28 02:26:57 2016 -0600 Add DB setup script commit d6d8813ef55bb1297089c9dbb87a9ab86e6c5ba2 Author: Ben Beltran Date: Mon Nov 28 02:26:34 2016 -0600 Add dotenv to the configs commit 649f66982d2152d36a782577043505835f235987 Author: Ben Beltran Date: Mon Nov 28 01:29:49 2016 -0600 Use a template instead of static html index --- scripts/setup_database.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 scripts/setup_database.js (limited to 'scripts') 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(); + -- cgit