]>
Commit | Line | Data |
---|---|---|
3fd3ab2d C |
1 | import { Sequelize as SequelizeTypescript } from 'sequelize-typescript' |
2 | import { isTestInstance } from '../helpers/core-utils' | |
3 | import { logger } from '../helpers/logger' | |
8c308c2b | 4 | |
3fd3ab2d | 5 | import { AccountModel } from '../models/account/account' |
3fd3ab2d C |
6 | import { AccountVideoRateModel } from '../models/account/account-video-rate' |
7 | import { UserModel } from '../models/account/user' | |
50d6de9c C |
8 | import { ActorModel } from '../models/activitypub/actor' |
9 | import { ActorFollowModel } from '../models/activitypub/actor-follow' | |
3fd3ab2d C |
10 | import { ApplicationModel } from '../models/application/application' |
11 | import { AvatarModel } from '../models/avatar/avatar' | |
3fd3ab2d C |
12 | import { OAuthClientModel } from '../models/oauth/oauth-client' |
13 | import { OAuthTokenModel } from '../models/oauth/oauth-token' | |
14 | import { ServerModel } from '../models/server/server' | |
15 | import { TagModel } from '../models/video/tag' | |
16 | import { VideoModel } from '../models/video/video' | |
17 | import { VideoAbuseModel } from '../models/video/video-abuse' | |
18 | import { VideoBlacklistModel } from '../models/video/video-blacklist' | |
19 | import { VideoChannelModel } from '../models/video/video-channel' | |
6d852470 | 20 | import { VideoCommentModel } from '../models/video/video-comment' |
3fd3ab2d C |
21 | import { VideoFileModel } from '../models/video/video-file' |
22 | import { VideoShareModel } from '../models/video/video-share' | |
23 | import { VideoTagModel } from '../models/video/video-tag' | |
65fcc311 | 24 | import { CONFIG } from './constants' |
fdbda9e3 | 25 | |
3fd3ab2d | 26 | require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string |
8c308c2b | 27 | |
65fcc311 C |
28 | const dbname = CONFIG.DATABASE.DBNAME |
29 | const username = CONFIG.DATABASE.USERNAME | |
30 | const password = CONFIG.DATABASE.PASSWORD | |
228077ef C |
31 | const host = CONFIG.DATABASE.HOSTNAME |
32 | const port = CONFIG.DATABASE.PORT | |
8c308c2b | 33 | |
3fd3ab2d C |
34 | const sequelizeTypescript = new SequelizeTypescript({ |
35 | database: dbname, | |
feb4bdfd | 36 | dialect: 'postgres', |
228077ef C |
37 | host, |
38 | port, | |
3fd3ab2d C |
39 | username, |
40 | password, | |
65fcc311 | 41 | benchmark: isTestInstance(), |
3fd3ab2d | 42 | isolationLevel: SequelizeTypescript.Transaction.ISOLATION_LEVELS.SERIALIZABLE, |
c2962505 | 43 | operatorsAliases: false, |
075f16ca | 44 | logging: (message: string, benchmark: number) => { |
165cdc75 C |
45 | if (process.env.NODE_DB_LOG === 'false') return |
46 | ||
7920c273 | 47 | let newMessage = message |
769d3321 | 48 | if (isTestInstance() === true && benchmark !== undefined) { |
7920c273 C |
49 | newMessage += ' | ' + benchmark + 'ms' |
50 | } | |
51 | ||
52 | logger.debug(newMessage) | |
53 | } | |
feb4bdfd C |
54 | }) |
55 | ||
91fea9fc | 56 | async function initDatabaseModels (silent: boolean) { |
3fd3ab2d C |
57 | sequelizeTypescript.addModels([ |
58 | ApplicationModel, | |
50d6de9c C |
59 | ActorModel, |
60 | ActorFollowModel, | |
3fd3ab2d C |
61 | AvatarModel, |
62 | AccountModel, | |
3fd3ab2d C |
63 | OAuthClientModel, |
64 | OAuthTokenModel, | |
65 | ServerModel, | |
66 | TagModel, | |
67 | AccountVideoRateModel, | |
3fd3ab2d C |
68 | UserModel, |
69 | VideoAbuseModel, | |
70 | VideoChannelModel, | |
3fd3ab2d C |
71 | VideoShareModel, |
72 | VideoFileModel, | |
73 | VideoBlacklistModel, | |
74 | VideoTagModel, | |
6d852470 C |
75 | VideoModel, |
76 | VideoCommentModel | |
3fd3ab2d | 77 | ]) |
b769007f | 78 | |
f5028693 C |
79 | if (!silent) logger.info('Database %s is ready.', dbname) |
80 | ||
d412e80e | 81 | return |
b769007f | 82 | } |
65fcc311 C |
83 | |
84 | // --------------------------------------------------------------------------- | |
85 | ||
e02643f3 | 86 | export { |
91fea9fc | 87 | initDatabaseModels, |
3fd3ab2d | 88 | sequelizeTypescript |
74889a71 | 89 | } |