PeerTube/initializers/database.js

62 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-06-09 10:41:40 -05:00
;(function () {
'use strict'
var config = require('config')
var mongoose = require('mongoose')
var constants = require('./constants')
2016-01-30 10:05:22 -06:00
var logger = require('../helpers/logger')
2015-06-09 10:41:40 -05:00
var dbname = 'peertube' + config.get('database.suffix')
2015-06-09 10:41:40 -05:00
var host = config.get('database.host')
var port = config.get('database.port')
// ----------- Videos -----------
var videosSchema = mongoose.Schema({
name: String,
namePath: String,
description: String,
magnetUri: String,
podUrl: String
})
var VideosDB = mongoose.model('videos', videosSchema)
// ----------- Pods -----------
var podsSchema = mongoose.Schema({
url: String,
publicKey: String,
score: { type: Number, max: constants.FRIEND_BASE_SCORE }
2015-06-09 10:41:40 -05:00
})
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)
2015-06-09 10:41:40 -05:00
// ----------- 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.')
})
// ----------- Export -----------
module.exports = {
VideosDB: VideosDB,
PodsDB: PodsDB,
PoolRequestsDB: PoolRequestsDB
2015-06-09 10:41:40 -05:00
}
})()