diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-18 11:28:17 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-24 16:26:20 +0200 |
commit | 1735c825726edaa0af5035cb6cbb0cc0db502c6d (patch) | |
tree | 7bbb442f2cb4d7be58a4e08d87f5974403a3047c /server/initializers | |
parent | e8bafea35bc930cb8ac5b2d521a188642a1adffe (diff) | |
download | PeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.tar.gz PeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.tar.zst PeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.zip |
Update sequelize
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/database.ts | 13 | ||||
-rw-r--r-- | server/initializers/migrations/0080-video-channels.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0100-activitypub.ts | 10 | ||||
-rw-r--r-- | server/initializers/migrations/0135-video-channel-actor.ts | 3 | ||||
-rw-r--r-- | server/initializers/migrations/0345-video-playlists.ts | 4 | ||||
-rw-r--r-- | server/initializers/migrator.ts | 8 |
6 files changed, 27 insertions, 13 deletions
diff --git a/server/initializers/database.ts b/server/initializers/database.ts index 8f237eb23..d1744d21f 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts | |||
@@ -37,6 +37,7 @@ import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-pla | |||
37 | import { VideoPlaylistModel } from '../models/video/video-playlist' | 37 | import { VideoPlaylistModel } from '../models/video/video-playlist' |
38 | import { VideoPlaylistElementModel } from '../models/video/video-playlist-element' | 38 | import { VideoPlaylistElementModel } from '../models/video/video-playlist-element' |
39 | import { ThumbnailModel } from '../models/video/thumbnail' | 39 | import { ThumbnailModel } from '../models/video/thumbnail' |
40 | import { QueryTypes, Transaction } from 'sequelize' | ||
40 | 41 | ||
41 | 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 |
42 | 43 | ||
@@ -58,8 +59,7 @@ const sequelizeTypescript = new SequelizeTypescript({ | |||
58 | max: poolMax | 59 | max: poolMax |
59 | }, | 60 | }, |
60 | benchmark: isTestInstance(), | 61 | benchmark: isTestInstance(), |
61 | isolationLevel: SequelizeTypescript.Transaction.ISOLATION_LEVELS.SERIALIZABLE, | 62 | isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE, |
62 | operatorsAliases: false, | ||
63 | logging: (message: string, benchmark: number) => { | 63 | logging: (message: string, benchmark: number) => { |
64 | if (process.env.NODE_DB_LOG === 'false') return | 64 | if (process.env.NODE_DB_LOG === 'false') return |
65 | 65 | ||
@@ -141,10 +141,15 @@ async function checkPostgresExtensions () { | |||
141 | 141 | ||
142 | async function checkPostgresExtension (extension: string) { | 142 | async function checkPostgresExtension (extension: string) { |
143 | const query = `SELECT true AS enabled FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;` | 143 | const query = `SELECT true AS enabled FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;` |
144 | 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<{ enabled: boolean }>(query, options) | ||
145 | 150 | ||
146 | if (!res || res.length === 0 || res[ 0 ][ 'enabled' ] !== true) { | 151 | if (!res || res.length === 0 || res[ 0 ][ 'enabled' ] !== true) { |
147 | // Try to create the extension ourself | 152 | // Try to create the extension ourselves |
148 | try { | 153 | try { |
149 | await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true }) | 154 | await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true }) |
150 | 155 | ||
diff --git a/server/initializers/migrations/0080-video-channels.ts b/server/initializers/migrations/0080-video-channels.ts index 0e17a4ccd..5512bdcf1 100644 --- a/server/initializers/migrations/0080-video-channels.ts +++ b/server/initializers/migrations/0080-video-channels.ts | |||
@@ -69,7 +69,7 @@ async function up (utils: { | |||
69 | const options = { | 69 | const options = { |
70 | type: Sequelize.QueryTypes.SELECT | 70 | type: Sequelize.QueryTypes.SELECT |
71 | } | 71 | } |
72 | const rawVideos = await utils.sequelize.query(query, options) | 72 | const rawVideos = await utils.sequelize.query(query, options) as any |
73 | 73 | ||
74 | for (const rawVideo of rawVideos) { | 74 | for (const rawVideo of rawVideos) { |
75 | const videoChannel = await utils.db.VideoChannel.findOne({ where: { authorId: rawVideo.authorId } }) | 75 | const videoChannel = await utils.db.VideoChannel.findOne({ where: { authorId: rawVideo.authorId } }) |
diff --git a/server/initializers/migrations/0100-activitypub.ts b/server/initializers/migrations/0100-activitypub.ts index a7ebd804c..2880a97d9 100644 --- a/server/initializers/migrations/0100-activitypub.ts +++ b/server/initializers/migrations/0100-activitypub.ts | |||
@@ -21,7 +21,7 @@ async function up (utils: { | |||
21 | const options = { | 21 | const options = { |
22 | type: Sequelize.QueryTypes.SELECT | 22 | type: Sequelize.QueryTypes.SELECT |
23 | } | 23 | } |
24 | const res = await utils.sequelize.query(query, options) | 24 | const res = await utils.sequelize.query(query, options) as any |
25 | 25 | ||
26 | if (!res[0] || res[0].total !== 0) { | 26 | if (!res[0] || res[0].total !== 0) { |
27 | throw new Error('You need to quit friends.') | 27 | throw new Error('You need to quit friends.') |
@@ -68,8 +68,8 @@ async function up (utils: { | |||
68 | const accountCreated = await createLocalAccountWithoutKeys(SERVER_ACTOR_NAME, null, applicationInstance.id, undefined) | 68 | const accountCreated = await createLocalAccountWithoutKeys(SERVER_ACTOR_NAME, null, applicationInstance.id, undefined) |
69 | 69 | ||
70 | const { publicKey, privateKey } = await createPrivateAndPublicKeys() | 70 | const { publicKey, privateKey } = await createPrivateAndPublicKeys() |
71 | accountCreated.set('publicKey', publicKey) | 71 | accountCreated.Actor.publicKey = publicKey |
72 | accountCreated.set('privateKey', privateKey) | 72 | accountCreated.Actor.privateKey = privateKey |
73 | 73 | ||
74 | await accountCreated.save() | 74 | await accountCreated.save() |
75 | } | 75 | } |
@@ -86,8 +86,8 @@ async function up (utils: { | |||
86 | const account = await createLocalAccountWithoutKeys(user.username, user.id, null, undefined) | 86 | const account = await createLocalAccountWithoutKeys(user.username, user.id, null, undefined) |
87 | 87 | ||
88 | const { publicKey, privateKey } = await createPrivateAndPublicKeys() | 88 | const { publicKey, privateKey } = await createPrivateAndPublicKeys() |
89 | account.set('publicKey', publicKey) | 89 | account.Actor.publicKey = publicKey |
90 | account.set('privateKey', privateKey) | 90 | account.Actor.privateKey = privateKey |
91 | await account.save() | 91 | await account.save() |
92 | } | 92 | } |
93 | 93 | ||
diff --git a/server/initializers/migrations/0135-video-channel-actor.ts b/server/initializers/migrations/0135-video-channel-actor.ts index 033f43b68..5ace0f4d2 100644 --- a/server/initializers/migrations/0135-video-channel-actor.ts +++ b/server/initializers/migrations/0135-video-channel-actor.ts | |||
@@ -239,7 +239,8 @@ async function up (utils: { | |||
239 | 239 | ||
240 | { | 240 | { |
241 | const query = 'SELECT * FROM "actor" WHERE "serverId" IS NULL AND "publicKey" IS NULL' | 241 | const query = 'SELECT * FROM "actor" WHERE "serverId" IS NULL AND "publicKey" IS NULL' |
242 | const [ res ] = await utils.sequelize.query(query) | 242 | const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT } |
243 | const [ res ] = await utils.sequelize.query(query, options) | ||
243 | 244 | ||
244 | for (const actor of res) { | 245 | for (const actor of res) { |
245 | const { privateKey, publicKey } = await createPrivateAndPublicKeys() | 246 | const { privateKey, publicKey } = await createPrivateAndPublicKeys() |
diff --git a/server/initializers/migrations/0345-video-playlists.ts b/server/initializers/migrations/0345-video-playlists.ts index 6953f5553..de69f5b9e 100644 --- a/server/initializers/migrations/0345-video-playlists.ts +++ b/server/initializers/migrations/0345-video-playlists.ts | |||
@@ -51,7 +51,9 @@ CREATE TABLE IF NOT EXISTS "videoPlaylistElement" | |||
51 | 51 | ||
52 | { | 52 | { |
53 | const userQuery = 'SELECT "username" FROM "user";' | 53 | const userQuery = 'SELECT "username" FROM "user";' |
54 | const userResult = await utils.sequelize.query(userQuery, { transaction, type: Sequelize.QueryTypes.SELECT }) | 54 | |
55 | const options = { transaction, type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT } | ||
56 | const userResult = await utils.sequelize.query<{ username: string }>(userQuery, options) | ||
55 | const usernames = userResult.map(r => r.username) | 57 | const usernames = userResult.map(r => r.username) |
56 | 58 | ||
57 | for (const username of usernames) { | 59 | for (const username of usernames) { |
diff --git a/server/initializers/migrator.ts b/server/initializers/migrator.ts index adc2f9fb3..1cb0116b7 100644 --- a/server/initializers/migrator.ts +++ b/server/initializers/migrator.ts | |||
@@ -3,6 +3,7 @@ import { logger } from '../helpers/logger' | |||
3 | import { LAST_MIGRATION_VERSION } from './constants' | 3 | import { LAST_MIGRATION_VERSION } from './constants' |
4 | import { sequelizeTypescript } from './database' | 4 | import { sequelizeTypescript } from './database' |
5 | import { readdir } from 'fs-extra' | 5 | import { readdir } from 'fs-extra' |
6 | import { QueryTypes } from 'sequelize' | ||
6 | 7 | ||
7 | async function migrate () { | 8 | async function migrate () { |
8 | const tables = await sequelizeTypescript.getQueryInterface().showAllTables() | 9 | const tables = await sequelizeTypescript.getQueryInterface().showAllTables() |
@@ -13,7 +14,12 @@ async function migrate () { | |||
13 | 14 | ||
14 | let actualVersion: number | null = null | 15 | let actualVersion: number | null = null |
15 | 16 | ||
16 | const [ rows ] = await sequelizeTypescript.query('SELECT "migrationVersion" FROM "application"') | 17 | const query = 'SELECT "migrationVersion" FROM "application"' |
18 | const options = { | ||
19 | type: QueryTypes.SELECT as QueryTypes.SELECT | ||
20 | } | ||
21 | |||
22 | const rows = await sequelizeTypescript.query<{ migrationVersion: number }>(query, options) | ||
17 | if (rows && rows[0] && rows[0].migrationVersion) { | 23 | if (rows && rows[0] && rows[0].migrationVersion) { |
18 | actualVersion = rows[0].migrationVersion | 24 | actualVersion = rows[0].migrationVersion |
19 | } | 25 | } |