<commit_before>var keys = require('./keys.js');
var path = require('path');
var knex = require('knex').initialize({
  client: 'mysql',
  connection: process.env.CUSTOMCONNSTR_MYSQL_CONNURL || {
    host     : 'localhost',
    user     : keys.mysqlUser.username,
    password : keys.mysqlUser.password,
    database : 'sentimentalDev',
    charset  : 'utf8'
  }
});

var db = require('bookshelf')(knex);


db.knex.schema.hasTable('keywords').then(function (exists) {
  if (!exists) {
    db.knex.schema.createTable('keywords', function (key) {
      key.increments('id').primary();
      key.string('word', 255);
    }).then(function (table) {
      console.log('Created Table', table);
    });
  }
});

db.knex.schema.hasTable('sources').then(function (exists) {
  if (!exists) {
    db.knex.schema.createTable('sources', function (source) {
      source.increments('id').primary();
      source.string('name', 255);
    }).then(function (table) {
      console.log('Created Table', table);
    });
  }
});

db.knex.schema.hasTable('articles').then(function (exists) {
  if (!exists) {
    db.knex.schema.createTable('articles', function (article) {
      article.increments('id').primary();
      article.integer('source').unsigned().references('id').inTable('sources');
      article.integer('word').unsigned().references('id').inTable('keywords');
      article.date('published');
      article.string('url', 225);
      article.string('headline', 225);
      article.string('snippet', 1000);
      article.string('leadParagraph', 2000);
      // article.float('sentiment', 4, 4);
      article.float('sentimentOfHeadline', 4, 4);
      article.float('sentimentOfSnippet', 4, 4);
      article.float('sentimentOfLeadParagraph', 4, 4);
      article.timestamps();
    }).then(function (table) {
      console.log('Created Table', table);
    });
  }
});

//we may not need this due to the way relations are set up in the models.
db.knex.schema.hasTable('keywordSources').then(function (exists) {
  if (!exists) {
    db.knex.schema.createTable('keywordSources', function (wordSource) {
      wordSource.integer('source').unsigned().references('id').inTable('sources');
      wordSource.integer('words').unsigned().references('id').inTable('keywords');
    }).then(function (table) {
      console.log('Created Table', table);
    });
  }
});

module.exports = db;
<commit_msg>Fix more keys to work in dev or deploy environments<commit_after>var path = require('path');

//  Handle both development and deployment environments without breaking
var knex;
if (process.env.CUSTOMCONNSTR_MYSQL_CONNURL){
  knex = require('knex').initialize({
    client: 'mysql',
    connection: process.env.CUSTOMCONNSTR_MYSQL_CONNURL
  });
} else {
  var keys = require('./keys.js');
  knex = require('knex').initialize({
    client: 'mysql',
    connection: {
      host     : 'localhost',
      user     : keys.mysqlUser.username,
      password : <PASSWORD>,
      database : 'sentimentalDev',
      charset  : 'utf8'
    }
  });
}

var db = require('bookshelf')(knex);

db.knex.schema.hasTable('keywords').then(function (exists) {
  if (!exists) {
    db.knex.schema.createTable('keywords', function (key) {
      key.increments('id').primary();
      key.string('word', 255);
    }).then(function (table) {
      console.log('Created Table', table);
    });
  }
});

db.knex.schema.hasTable('sources').then(function (exists) {
  if (!exists) {
    db.knex.schema.createTable('sources', function (source) {
      source.increments('id').primary();
      source.string('name', 255);
    }).then(function (table) {
      console.log('Created Table', table);
    });
  }
});

db.knex.schema.hasTable('articles').then(function (exists) {
  if (!exists) {
    db.knex.schema.createTable('articles', function (article) {
      article.increments('id').primary();
      article.integer('source').unsigned().references('id').inTable('sources');
      article.integer('word').unsigned().references('id').inTable('keywords');
      article.date('published');
      article.string('url', 225);
      article.string('headline', 225);
      article.string('snippet', 1000);
      article.string('leadParagraph', 2000);
      // article.float('sentiment', 4, 4);
      article.float('sentimentOfHeadline', 4, 4);
      article.float('sentimentOfSnippet', 4, 4);
      article.float('sentimentOfLeadParagraph', 4, 4);
      article.timestamps();
    }).then(function (table) {
      console.log('Created Table', table);
    });
  }
});

//we may not need this due to the way relations are set up in the models.
db.knex.schema.hasTable('keywordSources').then(function (exists) {
  if (!exists) {
    db.knex.schema.createTable('keywordSources', function (wordSource) {
      wordSource.integer('source').unsigned().references('id').inTable('sources');
      wordSource.integer('words').unsigned().references('id').inTable('keywords');
    }).then(function (table) {
      console.log('Created Table', table);
    });
  }
});

module.exports = db;

{'fraction_non_alphanumeric': 0.18437313135339845, 'fraction_numerical': 0.011560693641618497, 'mean_word_length': 3.707317073170732, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7455062', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1536, 'n_words': 276}