aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/database.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-22 20:58:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-25 17:32:16 +0200
commite02643f32e4c97ca307f8fc5b69be79c40d70a3b (patch)
treeb7f6269913cd5a0e4f26a9461a043deb0c168be0 /server/initializers/database.ts
parent65fcc3119c334b75dd13bcfdebf186afdc580a8f (diff)
downloadPeerTube-e02643f32e4c97ca307f8fc5b69be79c40d70a3b.tar.gz
PeerTube-e02643f32e4c97ca307f8fc5b69be79c40d70a3b.tar.zst
PeerTube-e02643f32e4c97ca307f8fc5b69be79c40d70a3b.zip
Type models
Diffstat (limited to 'server/initializers/database.ts')
-rw-r--r--server/initializers/database.ts59
1 files changed, 50 insertions, 9 deletions
diff --git a/server/initializers/database.ts b/server/initializers/database.ts
index 753a06669..c89a8b23c 100644
--- a/server/initializers/database.ts
+++ b/server/initializers/database.ts
@@ -6,12 +6,52 @@ import { CONFIG } from './constants'
6// Do not use barrel, we need to load database first 6// Do not use barrel, we need to load database first
7import { logger } from '../helpers/logger' 7import { logger } from '../helpers/logger'
8import { isTestInstance } from '../helpers/utils' 8import { isTestInstance } from '../helpers/utils'
9import {
10 ApplicationModel,
11 AuthorModel,
12 JobModel,
13 OAuthClientModel,
14 OAuthTokenModel,
15 PodModel,
16 RequestModel,
17 RequestToPodModel,
18 RequestVideoEventModel,
19 RequestVideoQaduModel,
20 TagModel,
21 UserModel,
22 UserVideoRateModel,
23 VideoAbuseModel,
24 BlacklistedVideoModel,
25 VideoTagModel,
26 VideoModel
27} from '../models'
9 28
10const dbname = CONFIG.DATABASE.DBNAME 29const dbname = CONFIG.DATABASE.DBNAME
11const username = CONFIG.DATABASE.USERNAME 30const username = CONFIG.DATABASE.USERNAME
12const password = CONFIG.DATABASE.PASSWORD 31const password = CONFIG.DATABASE.PASSWORD
13 32
14const database: any = {} 33const database: {
34 sequelize?: Sequelize.Sequelize,
35 init?: (silent: any, callback: any) => void,
36
37 Application?: ApplicationModel,
38 Author?: AuthorModel,
39 Job?: JobModel,
40 OAuthClient?: OAuthClientModel,
41 OAuthToken?: OAuthTokenModel,
42 Pod?: PodModel,
43 RequestToPod?: RequestToPodModel,
44 RequestVideoEvent?: RequestVideoEventModel,
45 RequestVideoQadu?: RequestVideoQaduModel,
46 Request?: RequestModel,
47 Tag?: TagModel,
48 UserVideoRate?: UserVideoRateModel,
49 User?: UserModel,
50 VideoAbuse?: VideoAbuseModel,
51 BlacklistedVideo?: BlacklistedVideoModel,
52 VideoTag?: VideoTagModel,
53 Video?: VideoModel
54} = {}
15 55
16const sequelize = new Sequelize(dbname, username, password, { 56const sequelize = new Sequelize(dbname, username, password, {
17 dialect: 'postgres', 57 dialect: 'postgres',
@@ -32,12 +72,6 @@ const sequelize = new Sequelize(dbname, username, password, {
32database.sequelize = sequelize 72database.sequelize = sequelize
33 73
34database.init = function (silent, callback) { 74database.init = function (silent, callback) {
35 if (!callback) {
36 callback = silent
37 silent = false
38 }
39
40 if (!callback) callback = function () { /* empty */ }
41 75
42 const modelDirectory = join(__dirname, '..', 'models') 76 const modelDirectory = join(__dirname, '..', 'models')
43 fs.readdir(modelDirectory, function (err, files) { 77 fs.readdir(modelDirectory, function (err, files) {
@@ -45,7 +79,12 @@ database.init = function (silent, callback) {
45 79
46 files.filter(function (file) { 80 files.filter(function (file) {
47 // For all models but not utils.js 81 // For all models but not utils.js
48 if (file === 'utils.js') return false 82 if (
83 file === 'index.js' ||
84 file === 'utils.js' ||
85 file.endsWith('-interface.js') ||
86 file.endsWith('.js.map')
87 ) return false
49 88
50 return true 89 return true
51 }) 90 })
@@ -69,4 +108,6 @@ database.init = function (silent, callback) {
69 108
70// --------------------------------------------------------------------------- 109// ---------------------------------------------------------------------------
71 110
72module.exports = database 111export {
112 database
113}