diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-02-04 21:10:33 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-02-04 21:10:33 +0100 |
commit | c173e56520b0fe4206b9ea8049b6add40bfeabcd (patch) | |
tree | 264c6cbf1bf81a6522685b4be5771bbeef4cd5dc /initializers | |
parent | c45f7f84001c2731909db04dd82e1c1f290386eb (diff) | |
download | PeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.tar.gz PeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.tar.zst PeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.zip |
Split models
Diffstat (limited to 'initializers')
-rw-r--r-- | initializers/database.js | 58 |
1 files changed, 14 insertions, 44 deletions
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 @@ | |||
4 | var config = require('config') | 4 | var config = require('config') |
5 | var mongoose = require('mongoose') | 5 | var mongoose = require('mongoose') |
6 | 6 | ||
7 | var constants = require('./constants') | ||
8 | var logger = require('../helpers/logger') | 7 | var logger = require('../helpers/logger') |
9 | 8 | ||
10 | var dbname = 'peertube' + config.get('database.suffix') | 9 | var dbname = 'peertube' + config.get('database.suffix') |
11 | var host = config.get('database.host') | 10 | var host = config.get('database.host') |
12 | var port = config.get('database.port') | 11 | var port = config.get('database.port') |
13 | 12 | ||
14 | // ----------- Pods ----------- | 13 | var database = { |
15 | var podsSchema = mongoose.Schema({ | 14 | connect: connect |
16 | url: String, | 15 | } |
17 | publicKey: String, | ||
18 | score: { type: Number, max: constants.FRIEND_BASE_SCORE } | ||
19 | }) | ||
20 | |||
21 | var PodsDB = mongoose.model('pods', podsSchema) | ||
22 | |||
23 | // ----------- PoolRequests ----------- | ||
24 | var poolRequestsSchema = mongoose.Schema({ | ||
25 | type: String, | ||
26 | id: String, // Special id to find duplicates (video created we want to remove...) | ||
27 | request: mongoose.Schema.Types.Mixed | ||
28 | }) | ||
29 | |||
30 | var PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema) | ||
31 | |||
32 | // ----------- Videos ----------- | ||
33 | var videosSchema = mongoose.Schema({ | ||
34 | name: String, | ||
35 | namePath: String, | ||
36 | description: String, | ||
37 | magnetUri: String, | ||
38 | podUrl: String | ||
39 | }) | ||
40 | |||
41 | var VideosDB = mongoose.model('videos', videosSchema) | ||
42 | 16 | ||
43 | // --------------------------------------------------------------------------- | 17 | function connect () { |
18 | mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) | ||
19 | mongoose.connection.on('error', function () { | ||
20 | logger.error('Mongodb connection error.') | ||
21 | process.exit(0) | ||
22 | }) | ||
44 | 23 | ||
45 | module.exports = { | 24 | mongoose.connection.on('open', function () { |
46 | PodsDB: PodsDB, | 25 | logger.info('Connected to mongodb.') |
47 | PoolRequestsDB: PoolRequestsDB, | 26 | }) |
48 | VideosDB: VideosDB | ||
49 | } | 27 | } |
50 | 28 | ||
51 | // ----------- Connection ----------- | 29 | // --------------------------------------------------------------------------- |
52 | |||
53 | mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) | ||
54 | mongoose.connection.on('error', function () { | ||
55 | logger.error('Mongodb connection error.') | ||
56 | process.exit(0) | ||
57 | }) | ||
58 | 30 | ||
59 | mongoose.connection.on('open', function () { | 31 | module.exports = database |
60 | logger.info('Connected to mongodb.') | ||
61 | }) | ||
62 | })() | 32 | })() |