Remove sequelize deprecated operators

This commit is contained in:
Chocobozzz 2017-10-26 16:59:02 +02:00
parent a265f7f30f
commit c296250511
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
9 changed files with 20 additions and 17 deletions

View File

@ -131,4 +131,3 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
this.form.patchValue(this.video.toJSON())
}
}

View File

@ -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

View File

@ -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
}
}
}

View File

@ -41,7 +41,7 @@ removeByRequestIdsAndPod = function (requestsIds: number[], podId: number) {
const query = {
where: {
requestId: {
$in: requestsIds
[Sequelize.Op.in]: requestsIds
},
podId: podId
}

View File

@ -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: [

View File

@ -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
}

View File

@ -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"')
]
}

View File

@ -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 } ]
}
}

View File

@ -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")'
)
}