]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - src/database.js
Finalise the join in a network and add the ability to quit it
[github/Chocobozzz/PeerTube.git] / src / database.js
CommitLineData
8c308c2b
C
1;(function () {
2 'use strict'
3
4 var config = require('config')
5 var mongoose = require('mongoose')
6
656ea8f7 7 var constants = require('./constants')
8c308c2b
C
8 var logger = require('./logger')
9
d148f3b9 10 var dbname = 'peertube' + config.get('database.suffix')
8c308c2b
C
11 var host = config.get('database.host')
12 var port = config.get('database.port')
13
14 // ----------- Videos -----------
15 var videosSchema = mongoose.Schema({
16 name: String,
17 namePath: String,
18 description: String,
19 magnetUri: String,
20 podUrl: String
21 })
22
23 var VideosDB = mongoose.model('videos', videosSchema)
24
25 // ----------- Pods -----------
26 var podsSchema = mongoose.Schema({
27 url: String,
3bcb78b3 28 publicKey: String,
656ea8f7 29 score: { type: Number, max: constants.FRIEND_BASE_SCORE }
8c308c2b
C
30 })
31
32 var PodsDB = mongoose.model('pods', podsSchema)
33
0b697522
C
34 // ----------- PoolRequests -----------
35 var poolRequestsSchema = mongoose.Schema({
36 type: String,
37 id: String, // Special id to find duplicates (video created we want to remove...)
38 request: mongoose.Schema.Types.Mixed
39 })
40
41 var PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema)
42
8c308c2b
C
43 // ----------- Connection -----------
44
45 mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
46 mongoose.connection.on('error', function () {
47 logger.error('Mongodb connection error.')
48 process.exit(0)
49 })
50
51 mongoose.connection.on('open', function () {
52 logger.info('Connected to mongodb.')
53 })
54
55 // ----------- Export -----------
56 module.exports = {
57 VideosDB: VideosDB,
0b697522
C
58 PodsDB: PodsDB,
59 PoolRequestsDB: PoolRequestsDB
8c308c2b
C
60 }
61})()