aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/database.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers/database.ts')
-rw-r--r--server/initializers/database.ts31
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'
21import { VideoFileModel } from '../models/video/video-file' 21import { VideoFileModel } from '../models/video/video-file'
22import { VideoShareModel } from '../models/video/video-share' 22import { VideoShareModel } from '../models/video/video-share'
23import { VideoTagModel } from '../models/video/video-tag' 23import { VideoTagModel } from '../models/video/video-tag'
24import { CONFIG } from './constants' 24import { CONFIG } from './config'
25import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update' 25import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update'
26import { VideoCaptionModel } from '../models/video/video-caption' 26import { VideoCaptionModel } from '../models/video/video-caption'
27import { VideoImportModel } from '../models/video/video-import' 27import { VideoImportModel } from '../models/video/video-import'
@@ -33,6 +33,11 @@ import { AccountBlocklistModel } from '../models/account/account-blocklist'
33import { ServerBlocklistModel } from '../models/server/server-blocklist' 33import { ServerBlocklistModel } from '../models/server/server-blocklist'
34import { UserNotificationModel } from '../models/account/user-notification' 34import { UserNotificationModel } from '../models/account/user-notification'
35import { UserNotificationSettingModel } from '../models/account/user-notification-setting' 35import { UserNotificationSettingModel } from '../models/account/user-notification-setting'
36import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist'
37import { VideoPlaylistModel } from '../models/video/video-playlist'
38import { VideoPlaylistElementModel } from '../models/video/video-playlist-element'
39import { ThumbnailModel } from '../models/video/thumbnail'
40import { QueryTypes, Transaction } from 'sequelize'
36 41
37require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string 42require('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
134async function checkPostgresExtension (extension: string) { 142async 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