<commit_before>var settings = require('../settings');
var helpers = require('./util');

var Sequelize = require("sequelize");
var sequelize = exports.sequelize = new Sequelize(settings.DATABASE['NAME'], settings.DATABASE['USER'], settings.DATABASE['PASSWORD'], {
  host: settings.DATABASE['HOST'],
  port: settings.DATABASE['PORT'],
  dialect: settings.DATABASE['ENGINE'],
  storage: settings.DATABASE['NAME'],
  logging: false
});

// Functions

function logging(b) {
  if(b === undefined) {
    return sequelize.options.logging;
  } else {
    sequelize.options.logging = !!b === true ? console.log : false;
  }
}
exports.logging = logging;

function syncAll(forceDrop, cb) {
  var log = logging();
  logging(true);
  sequelize.sync({force: forceDrop})
  .success(function() {
    logging(log); cb(null);
  })
  .error(function(errors) {cb(errors)});
}
exports.syncAll = syncAll;

// Models

var Post = exports.Post = sequelize.define('Post', {
  title: { type: Sequelize.STRING, allowNull: false },
  slug: { type: Sequelize.STRING, allowNull: false, unique: true},
  description: { type: Sequelize.TEXT, allowNull: false },
  body:  { type: Sequelize.TEXT, allowNull: false }
});

var User = exports.User = sequelize.define('User', {
  username: { type: Sequelize.STRING, allowNull: false, unique: true },
  password: { type: Sequelize.STRING, allowNull: false},
  firstname: Sequelize.STRING,
  lastname: Sequelize.STRING,
  email: Sequelize.STRING,
  isStaff: {type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false},
  lastLogin: {type: Sequelize.DATA, allowNull: true}
});

var Tag = exports.Tag = sequelize.define('Tag', {
  title: { type: Sequelize.STRING, allowNull: false},
  slug: { type: Sequelize.STRING, allowNull: false, unique: true}
});

var Token = exports.Token = sequelize.define('Token', {
  token: { type: Sequelize.STRING, allowNull: false, unique: true}
});

Token.belongsTo(User);
User.hasOne(Token);
User.hasMany(Post);
Post.belongsTo(User);
Post.hasMany(Tag);
Tag.hasMany(Post);<commit_msg>Added published state on Posts<commit_after>var settings = require('../settings');
var helpers = require('./util');

var Sequelize = require("sequelize");
var sequelize = exports.sequelize = new Sequelize(settings.DATABASE['NAME'], settings.DATABASE['USER'], settings.DATABASE['PASSWORD'], {
  host: settings.DATABASE['HOST'],
  port: settings.DATABASE['PORT'],
  dialect: settings.DATABASE['ENGINE'],
  storage: settings.DATABASE['NAME'],
  logging: false
});

// Functions

function logging(b) {
  if(b === undefined) {
    return sequelize.options.logging;
  } else {
    sequelize.options.logging = !!b === true ? console.log : false;
  }
}
exports.logging = logging;

function syncAll(forceDrop, cb) {
  var log = logging();
  logging(true);
  sequelize.sync({force: forceDrop})
  .success(function() {
    logging(log); cb(null);
  })
  .error(function(errors) {cb(errors)});
}
exports.syncAll = syncAll;

// Models

var Post = exports.Post = sequelize.define('Post', {
  title: { type: Sequelize.STRING, allowNull: false },
  slug: { type: Sequelize.STRING, allowNull: false, unique: true},
  description: { type: Sequelize.TEXT, allowNull: false },
  body: { type: Sequelize.TEXT, allowNull: false },
  published: {type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false}
});

var User = exports.User = sequelize.define('User', {
  username: { type: Sequelize.STRING, allowNull: false, unique: true },
  password: { type: Sequelize.STRING, allowNull: false},
  firstname: Sequelize.STRING,
  lastname: Sequelize.STRING,
  email: Sequelize.STRING,
  isStaff: {type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false},
  lastLogin: {type: Sequelize.DATA, allowNull: true}
});

var Tag = exports.Tag = sequelize.define('Tag', {
  title: { type: Sequelize.STRING, allowNull: false},
  slug: { type: Sequelize.STRING, allowNull: false, unique: true}
});

var Token = exports.Token = sequelize.define('Token', {
  token: { type: Sequelize.STRING, allowNull: false, unique: true}
});

Token.belongsTo(User);
User.hasOne(Token);
User.hasMany(Post);
Post.belongsTo(User);
Post.hasMany(Tag);
Tag.hasMany(Post);
{'fraction_non_alphanumeric': 0.1638949144372138, 'fraction_numerical': 0.0, 'mean_word_length': 4.979827089337176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6045651', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1391, 'n_words': 312}