diff options
Diffstat (limited to 'server/initializers/database.ts')
-rw-r--r-- | server/initializers/database.ts | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/server/initializers/database.ts b/server/initializers/database.ts index 84ad2079b..142063a99 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts | |||
@@ -21,7 +21,7 @@ import { VideoCommentModel } from '../models/video/video-comment' | |||
21 | import { VideoFileModel } from '../models/video/video-file' | 21 | import { VideoFileModel } from '../models/video/video-file' |
22 | import { VideoShareModel } from '../models/video/video-share' | 22 | import { VideoShareModel } from '../models/video/video-share' |
23 | import { VideoTagModel } from '../models/video/video-tag' | 23 | import { VideoTagModel } from '../models/video/video-tag' |
24 | import { CONFIG } from './constants' | 24 | import { CONFIG } from './config' |
25 | import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update' | 25 | import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update' |
26 | import { VideoCaptionModel } from '../models/video/video-caption' | 26 | import { VideoCaptionModel } from '../models/video/video-caption' |
27 | import { VideoImportModel } from '../models/video/video-import' | 27 | import { VideoImportModel } from '../models/video/video-import' |
@@ -33,6 +33,11 @@ import { AccountBlocklistModel } from '../models/account/account-blocklist' | |||
33 | import { ServerBlocklistModel } from '../models/server/server-blocklist' | 33 | import { ServerBlocklistModel } from '../models/server/server-blocklist' |
34 | import { UserNotificationModel } from '../models/account/user-notification' | 34 | import { UserNotificationModel } from '../models/account/user-notification' |
35 | import { UserNotificationSettingModel } from '../models/account/user-notification-setting' | 35 | import { UserNotificationSettingModel } from '../models/account/user-notification-setting' |
36 | import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' | ||
37 | import { VideoPlaylistModel } from '../models/video/video-playlist' | ||
38 | import { VideoPlaylistElementModel } from '../models/video/video-playlist-element' | ||
39 | import { ThumbnailModel } from '../models/video/thumbnail' | ||
40 | import { QueryTypes, Transaction } from 'sequelize' | ||
36 | 41 | ||
37 | require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string | 42 | require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string |
38 | 43 | ||
@@ -54,8 +59,7 @@ const sequelizeTypescript = new SequelizeTypescript({ | |||
54 | max: poolMax | 59 | max: poolMax |
55 | }, | 60 | }, |
56 | benchmark: isTestInstance(), | 61 | benchmark: isTestInstance(), |
57 | isolationLevel: SequelizeTypescript.Transaction.ISOLATION_LEVELS.SERIALIZABLE, | 62 | isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE, |
58 | operatorsAliases: false, | ||
59 | logging: (message: string, benchmark: number) => { | 63 | logging: (message: string, benchmark: number) => { |
60 | if (process.env.NODE_DB_LOG === 'false') return | 64 | if (process.env.NODE_DB_LOG === 'false') return |
61 | 65 | ||
@@ -82,6 +86,7 @@ async function initDatabaseModels (silent: boolean) { | |||
82 | AccountVideoRateModel, | 86 | AccountVideoRateModel, |
83 | UserModel, | 87 | UserModel, |
84 | VideoAbuseModel, | 88 | VideoAbuseModel, |
89 | VideoModel, | ||
85 | VideoChangeOwnershipModel, | 90 | VideoChangeOwnershipModel, |
86 | VideoChannelModel, | 91 | VideoChannelModel, |
87 | VideoShareModel, | 92 | VideoShareModel, |
@@ -89,7 +94,6 @@ async function initDatabaseModels (silent: boolean) { | |||
89 | VideoCaptionModel, | 94 | VideoCaptionModel, |
90 | VideoBlacklistModel, | 95 | VideoBlacklistModel, |
91 | VideoTagModel, | 96 | VideoTagModel, |
92 | VideoModel, | ||
93 | VideoCommentModel, | 97 | VideoCommentModel, |
94 | ScheduleVideoUpdateModel, | 98 | ScheduleVideoUpdateModel, |
95 | VideoImportModel, | 99 | VideoImportModel, |
@@ -99,7 +103,11 @@ async function initDatabaseModels (silent: boolean) { | |||
99 | AccountBlocklistModel, | 103 | AccountBlocklistModel, |
100 | ServerBlocklistModel, | 104 | ServerBlocklistModel, |
101 | UserNotificationModel, | 105 | UserNotificationModel, |
102 | UserNotificationSettingModel | 106 | UserNotificationSettingModel, |
107 | VideoStreamingPlaylistModel, | ||
108 | VideoPlaylistModel, | ||
109 | VideoPlaylistElementModel, | ||
110 | ThumbnailModel | ||
103 | ]) | 111 | ]) |
104 | 112 | ||
105 | // Check extensions exist in the database | 113 | // Check extensions exist in the database |
@@ -132,11 +140,16 @@ async function checkPostgresExtensions () { | |||
132 | } | 140 | } |
133 | 141 | ||
134 | async function checkPostgresExtension (extension: string) { | 142 | async function checkPostgresExtension (extension: string) { |
135 | const query = `SELECT true AS enabled FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;` | 143 | const query = `SELECT 1 FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;` |
136 | const [ res ] = await sequelizeTypescript.query(query, { raw: true }) | 144 | const options = { |
145 | type: QueryTypes.SELECT as QueryTypes.SELECT, | ||
146 | raw: true | ||
147 | } | ||
148 | |||
149 | const res = await sequelizeTypescript.query<object>(query, options) | ||
137 | 150 | ||
138 | if (!res || res.length === 0 || res[ 0 ][ 'enabled' ] !== true) { | 151 | if (!res || res.length === 0) { |
139 | // Try to create the extension ourself | 152 | // Try to create the extension ourselves |
140 | try { | 153 | try { |
141 | await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true }) | 154 | await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true }) |
142 | 155 | ||