From: Chocobozzz Date: Thu, 26 Oct 2017 14:59:02 +0000 (+0200) Subject: Remove sequelize deprecated operators X-Git-Tag: v0.0.1-alpha~256 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c2962505115563ad1510e8116f3b362887cac71f;p=oweals%2Fpeertube.git Remove sequelize deprecated operators --- diff --git a/client/src/app/videos/+video-edit/video-update.component.ts b/client/src/app/videos/+video-edit/video-update.component.ts index c4ae22896..30390ac05 100644 --- a/client/src/app/videos/+video-edit/video-update.component.ts +++ b/client/src/app/videos/+video-edit/video-update.component.ts @@ -131,4 +131,3 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { this.form.patchValue(this.video.toJSON()) } } - diff --git a/server/initializers/database.ts b/server/initializers/database.ts index b410b0c18..dfad01581 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts @@ -64,6 +64,7 @@ const sequelize = new Sequelize(dbname, username, password, { port: CONFIG.DATABASE.PORT, benchmark: isTestInstance(), isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.SERIALIZABLE, + operatorsAliases: false, logging: (message: string, benchmark: number) => { let newMessage = message diff --git a/server/models/pod/pod.ts b/server/models/pod/pod.ts index 6619726af..6b33336b8 100644 --- a/server/models/pod/pod.ts +++ b/server/models/pod/pod.ts @@ -130,7 +130,7 @@ incrementScores = function (ids: number[], value: number) { const options = { where: { id: { - $in: ids + [Sequelize.Op.in]: ids } }, // In this case score is a literal and not an integer so we do not validate it @@ -178,6 +178,7 @@ listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, ta let start = Math.floor(Math.random() * count) - limit if (start < 0) start = 0 + const subQuery = `(SELECT DISTINCT "${tableWithPods}"."podId" FROM "${tableWithPods}" ${tableWithPodsJoins})` const query = { attributes: [ 'id' ], order: [ @@ -187,7 +188,7 @@ listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, ta limit: limit, where: { id: { - $in: Sequelize.literal(`(SELECT DISTINCT "${tableWithPods}"."podId" FROM "${tableWithPods}" ${tableWithPodsJoins})`) + [Sequelize.Op.in]: Sequelize.literal(subQuery) } } } @@ -201,7 +202,9 @@ listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, ta listBadPods = function () { const query = { where: { - score: { $lte: 0 } + score: { + [Sequelize.Op.lte]: 0 + } } } diff --git a/server/models/request/request-to-pod.ts b/server/models/request/request-to-pod.ts index 6678ed290..4e14e918b 100644 --- a/server/models/request/request-to-pod.ts +++ b/server/models/request/request-to-pod.ts @@ -41,7 +41,7 @@ removeByRequestIdsAndPod = function (requestsIds: number[], podId: number) { const query = { where: { requestId: { - $in: requestsIds + [Sequelize.Op.in]: requestsIds }, podId: podId } diff --git a/server/models/request/request-video-event.ts b/server/models/request/request-video-event.ts index d7dce9bc8..8954407e1 100644 --- a/server/models/request/request-video-event.ts +++ b/server/models/request/request-video-event.ts @@ -111,7 +111,7 @@ listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: numbe model: RequestVideoEvent['sequelize'].models.Pod, where: { id: { - $in: podIds + [Sequelize.Op.in]: podIds } } } @@ -135,7 +135,7 @@ removeByRequestIdsAndPod = function (ids: number[], podId: number) { const query = { where: { id: { - $in: ids + [Sequelize.Op.in]: ids } }, include: [ diff --git a/server/models/request/request-video-qadu.ts b/server/models/request/request-video-qadu.ts index 9c97812b9..93cf249b3 100644 --- a/server/models/request/request-video-qadu.ts +++ b/server/models/request/request-video-qadu.ts @@ -101,7 +101,7 @@ listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: numbe model: RequestVideoQadu['sequelize'].models.Pod, where: { id: { - $in: podIds + [Sequelize.Op.in]: podIds } } }, @@ -122,7 +122,7 @@ removeByRequestIdsAndPod = function (ids: number[], podId: number) { const query = { where: { id: { - $in: ids + [Sequelize.Op.in]: ids }, podId } diff --git a/server/models/request/request.ts b/server/models/request/request.ts index b4c0226fa..71118a947 100644 --- a/server/models/request/request.ts +++ b/server/models/request/request.ts @@ -88,7 +88,7 @@ listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: numbe model: Request['sequelize'].models.Pod, where: { id: { - $in: podIds + [Sequelize.Op.in]: podIds } } } @@ -112,7 +112,7 @@ removeWithEmptyTo = function () { const query = { where: { id: { - $notIn: [ + [Sequelize.Op.notIn]: [ Sequelize.literal('SELECT "requestId" FROM "RequestToPods"') ] } diff --git a/server/models/user/user.ts b/server/models/user/user.ts index f8598c40f..074c9c121 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts @@ -271,7 +271,7 @@ loadByUsernameOrEmail = function (username: string, email: string) { const query = { include: [ { model: User['sequelize'].models.Author, required: true } ], where: { - $or: [ { username }, { email } ] + [Sequelize.Op.or]: [ { username }, { email } ] } } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 6c0db59f3..27f59f3a9 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1012,7 +1012,7 @@ searchAndPopulateAuthorAndPodAndTags = function (value: string, field: string, s } } else if (field === 'tags') { const escapedValue = Video['sequelize'].escape('%' + value + '%') - query.where['id'].$in = Video['sequelize'].literal( + query.where['id'][Sequelize.Op.in] = Video['sequelize'].literal( `(SELECT "VideoTags"."videoId" FROM "Tags" INNER JOIN "VideoTags" ON "Tags"."id" = "VideoTags"."tagId" @@ -1023,19 +1023,19 @@ searchAndPopulateAuthorAndPodAndTags = function (value: string, field: string, s // FIXME: Include our pod? (not stored in the database) podInclude.where = { host: { - $iLike: '%' + value + '%' + [Sequelize.Op.iLike]: '%' + value + '%' } } podInclude.required = true } else if (field === 'author') { authorInclude.where = { name: { - $iLike: '%' + value + '%' + [Sequelize.Op.iLike]: '%' + value + '%' } } } else { query.where[field] = { - $iLike: '%' + value + '%' + [Sequelize.Op.iLike]: '%' + value + '%' } } @@ -1056,7 +1056,7 @@ searchAndPopulateAuthorAndPodAndTags = function (value: string, field: string, s function createBaseVideosWhere () { return { id: { - $notIn: Video['sequelize'].literal( + [Sequelize.Op.notIn]: Video['sequelize'].literal( '(SELECT "BlacklistedVideos"."videoId" FROM "BlacklistedVideos")' ) }