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
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',
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'
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)
+ }
}
}