<commit_before>'use strict';
var mongoose = require('mongoose');
var ShortId = require('mongoose-shortid');
var timestamps = require('mongoose-timestamp');
var BBPromise = require('bluebird');
var mongooseDelete = require('mongoose-delete');
var keygen = require('keygenerator');

var Schema = mongoose.Schema;
var ApplicationSchema = new Schema({
  schemaVersion: String,
  //the org that owns this application
  organisation: {
    type: ShortId,
    required: 'Application must belong to an Organisation',
    index: true,
    ref: 'Organisation'
  },
  //friendly name
  name: {
    type: String
  },
  _id: {
    type: ShortId,
    base: 64,
    retries: 4,
    len: 20
  },
  //url alias
  alias: {
    type: [String],
    index: true
  },
  loggly: {
    _id: false,
    token: String,
    subdomain: String
  },
  //the app.hoi.io sub domain for hosting
  subDomain: {
    type: String,
    unique: true,
    index: true,
    required: true,
    default: function () {
      return require('moniker').choose();
    }
  },

  //api key
  apiKey: {
    type: String,
    unique: true,
    index: true,
    required: true,
    default: function () {
      return keygen._();
    }
  },
  //the storage for data
  dataKey: {
    type: String,
    unique: true,
    required: true,
    default: function () {
      return keygen._({
        forceLowercase: true
      });
    }
  },
  //anonymous

  anonymousPermissions: {
    dev: [{
      type: String
    }],
    test: [{
      type: String
    }],
    live: [{
      type: String
    }]
  },
  //settings from the hoist.json files
  settings: {
    dev: {
      type: Schema.Types.Mixed
    },
    test: {
      type: Schema.Types.Mixed
    },
    live: {
      type: Schema.Types.Mixed
    },
  },
  //when was the code last released
  lastDeploy: {
    dev: {
      type: Date
    },
    test: {
      type: Date
    },
    live: {
      type: Date
    }
  },
  //information about the commit
  lastCommit: {
    live: {
      message: String,
      sha1: String,
      user: String
    }
  },
  //should this application get preview features
  isCanary: {
    type: Boolean,
    default: false
  },
  //path to the git repository
  slug: {
    type: String,
    index: true
  },
  //should the applicaiton have split queues for executors
  //eventually everything will be true but for now we need to turn it
  //on one application at a time
  splitQueue: {
    type: Boolean,
    default: false
  },
  maxExecutors: {
    type: Number,
    index: true
  },
  currentExecutors: {
    type: Number,
    index: true
  }
});

ApplicationSchema.plugin(timestamps);
ApplicationSchema.plugin(mongooseDelete);
ApplicationSchema.set('toJSON', {
  virtuals: true
});
ApplicationSchema.virtual('gitRepo').get(function () {
  return this.slug;
}).set(function (value) {
  this.slug = value;
});


mongoose.model('Application', ApplicationSchema);<commit_msg>add defaults<commit_after>'use strict';
var mongoose = require('mongoose');
var ShortId = require('mongoose-shortid');
var timestamps = require('mongoose-timestamp');
var BBPromise = require('bluebird');
var mongooseDelete = require('mongoose-delete');
var keygen = require('keygenerator');

var Schema = mongoose.Schema;
var ApplicationSchema = new Schema({
  schemaVersion: String,
  //the org that owns this application
  organisation: {
    type: ShortId,
    required: 'Application must belong to an Organisation',
    index: true,
    ref: 'Organisation'
  },
  //friendly name
  name: {
    type: String
  },
  _id: {
    type: ShortId,
    base: 64,
    retries: 4,
    len: 20
  },
  //url alias
  alias: {
    type: [String],
    index: true
  },
  loggly: {
    _id: false,
    token: String,
    subdomain: String
  },
  //the app.hoi.io sub domain for hosting
  subDomain: {
    type: String,
    unique: true,
    index: true,
    required: true,
    default: function () {
      return require('moniker').choose();
    }
  },

  //api key
  apiKey: {
    type: String,
    unique: true,
    index: true,
    required: true,
    default: function () {
      return keygen._();
    }
  },
  //the storage for data
  dataKey: {
    type: String,
    unique: true,
    required: true,
    default: function () {
      return keygen._({
        forceLowercase: true
      });
    }
  },
  //anonymous

  anonymousPermissions: {
    dev: [{
      type: String
    }],
    test: [{
      type: String
    }],
    live: [{
      type: String
    }]
  },
  //settings from the hoist.json files
  settings: {
    dev: {
      type: Schema.Types.Mixed
    },
    test: {
      type: Schema.Types.Mixed
    },
    live: {
      type: Schema.Types.Mixed
    },
  },
  //when was the code last released
  lastDeploy: {
    dev: {
      type: Date
    },
    test: {
      type: Date
    },
    live: {
      type: Date
    }
  },
  //information about the commit
  lastCommit: {
    live: {
      message: String,
      sha1: String,
      user: String
    }
  },
  //should this application get preview features
  isCanary: {
    type: Boolean,
    default: false
  },
  //path to the git repository
  slug: {
    type: String,
    index: true
  },
  //should the applicaiton have split queues for executors
  //eventually everything will be true but for now we need to turn it
  //on one application at a time
  splitQueue: {
    type: Boolean,
    default: false
  },
  maxExecutors: {
    type: Number,
    index: true,
    default: 1
  },
  currentExecutors: {
    type: Number,
    index: true,
    default: 0
  }
});

ApplicationSchema.plugin(timestamps);
ApplicationSchema.plugin(mongooseDelete);
ApplicationSchema.set('toJSON', {
  virtuals: true
});
ApplicationSchema.virtual('gitRepo').get(function () {
  return this.slug;
}).set(function (value) {
  this.slug = value;
});


mongoose.model('Application', ApplicationSchema);
{'fraction_non_alphanumeric': 0.12694610778443113, 'fraction_numerical': 0.0023952095808383233, 'mean_word_length': 2.3988372093023256, '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': '1520081', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1899, 'n_words': 522}