From c173e56520b0fe4206b9ea8049b6add40bfeabcd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 4 Feb 2016 21:10:33 +0100 Subject: Split models --- initializers/database.js | 58 ++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 44 deletions(-) (limited to 'initializers') diff --git a/initializers/database.js b/initializers/database.js index e041d5c4b..96c172637 100644 --- a/initializers/database.js +++ b/initializers/database.js @@ -4,59 +4,29 @@ var config = require('config') var mongoose = require('mongoose') - var constants = require('./constants') var logger = require('../helpers/logger') var dbname = 'peertube' + config.get('database.suffix') var host = config.get('database.host') var port = config.get('database.port') - // ----------- Pods ----------- - var podsSchema = mongoose.Schema({ - url: String, - publicKey: String, - score: { type: Number, max: constants.FRIEND_BASE_SCORE } - }) - - var PodsDB = mongoose.model('pods', podsSchema) - - // ----------- PoolRequests ----------- - var poolRequestsSchema = mongoose.Schema({ - type: String, - id: String, // Special id to find duplicates (video created we want to remove...) - request: mongoose.Schema.Types.Mixed - }) - - var PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema) - - // ----------- Videos ----------- - var videosSchema = mongoose.Schema({ - name: String, - namePath: String, - description: String, - magnetUri: String, - podUrl: String - }) - - var VideosDB = mongoose.model('videos', videosSchema) + var database = { + connect: connect + } - // --------------------------------------------------------------------------- + function connect () { + mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) + mongoose.connection.on('error', function () { + logger.error('Mongodb connection error.') + process.exit(0) + }) - module.exports = { - PodsDB: PodsDB, - PoolRequestsDB: PoolRequestsDB, - VideosDB: VideosDB + mongoose.connection.on('open', function () { + logger.info('Connected to mongodb.') + }) } - // ----------- Connection ----------- - - mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) - mongoose.connection.on('error', function () { - logger.error('Mongodb connection error.') - process.exit(0) - }) + // --------------------------------------------------------------------------- - mongoose.connection.on('open', function () { - logger.info('Connected to mongodb.') - }) + module.exports = database })() -- cgit v1.2.3