]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/database.ts
Fix test
[github/Chocobozzz/PeerTube.git] / server / initializers / database.ts
index 52e7663949791ae80e47b5325f4ef72466db0e6e..bb95992e1334ddb0f27a0019036a00790ce25d52 100644 (file)
@@ -2,7 +2,7 @@ import { join } from 'path'
 import { flattenDepth } from 'lodash'
 require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string
 import * as Sequelize from 'sequelize'
-import * as Bluebird from 'bluebird'
+import { AvatarModel } from '../models/avatar'
 
 import { CONFIG } from './constants'
 // Do not use barrel, we need to load database first
@@ -19,46 +19,45 @@ import { UserModel } from '../models/account/user-interface'
 import { AccountVideoRateModel } from '../models/account/account-video-rate-interface'
 import { AccountFollowModel } from '../models/account/account-follow-interface'
 import { TagModel } from './../models/video/tag-interface'
-import { RequestModel } from './../models/request/request-interface'
-import { RequestVideoQaduModel } from './../models/request/request-video-qadu-interface'
-import { RequestVideoEventModel } from './../models/request/request-video-event-interface'
-import { RequestToPodModel } from './../models/request/request-to-pod-interface'
-import { PodModel } from './../models/pod/pod-interface'
+import { ServerModel } from '../models/server/server-interface'
 import { OAuthTokenModel } from './../models/oauth/oauth-token-interface'
 import { OAuthClientModel } from './../models/oauth/oauth-client-interface'
 import { JobModel } from './../models/job/job-interface'
 import { AccountModel } from './../models/account/account-interface'
 import { ApplicationModel } from './../models/application/application-interface'
+import { VideoChannelShareModel } from '../models/video/video-channel-share-interface'
+import { VideoShareModel } from '../models/video/video-share-interface'
 
 const dbname = CONFIG.DATABASE.DBNAME
 const username = CONFIG.DATABASE.USERNAME
 const password = CONFIG.DATABASE.PASSWORD
 
-const database: {
+export type PeerTubeDatabase = {
   sequelize?: Sequelize.Sequelize,
   init?: (silent: boolean) => Promise<void>,
 
   Application?: ApplicationModel,
+  Avatar?: AvatarModel,
   Account?: AccountModel,
   Job?: JobModel,
   OAuthClient?: OAuthClientModel,
   OAuthToken?: OAuthTokenModel,
-  Pod?: PodModel,
-  RequestToPod?: RequestToPodModel,
-  RequestVideoEvent?: RequestVideoEventModel,
-  RequestVideoQadu?: RequestVideoQaduModel,
-  Request?: RequestModel,
+  Server?: ServerModel,
   Tag?: TagModel,
   AccountVideoRate?: AccountVideoRateModel,
   AccountFollow?: AccountFollowModel,
   User?: UserModel,
   VideoAbuse?: VideoAbuseModel,
   VideoChannel?: VideoChannelModel,
+  VideoChannelShare?: VideoChannelShareModel,
+  VideoShare?: VideoShareModel,
   VideoFile?: VideoFileModel,
   BlacklistedVideo?: BlacklistedVideoModel,
   VideoTag?: VideoTagModel,
   Video?: VideoModel
-} = {}
+}
+
+const database: PeerTubeDatabase = {}
 
 const sequelize = new Sequelize(dbname, username, password, {
   dialect: 'postgres',
@@ -69,6 +68,8 @@ const sequelize = new Sequelize(dbname, username, password, {
   operatorsAliases: false,
 
   logging: (message: string, benchmark: number) => {
+    if (process.env.NODE_DB_LOG === 'false') return
+
     let newMessage = message
     if (isTestInstance() === true && benchmark !== undefined) {
       newMessage += ' | ' + benchmark + 'ms'
@@ -98,7 +99,12 @@ database.init = async (silent: boolean) => {
 
   for (const modelName of Object.keys(database)) {
     if ('associate' in database[modelName]) {
-      database[modelName].associate(database)
+      try {
+        database[modelName].associate(database)
+      } catch (err) {
+        logger.error('Cannot associate model %s.', modelName, err)
+        process.exit(0)
+      }
     }
   }