Fix video files duplicated when fps is null

Null values are not considered equal in a UNIQUE index
This commit is contained in:
Chocobozzz 2018-09-26 14:08:35 +02:00
parent 60e74f80d8
commit 2e7cf5ae0c
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 38 additions and 5 deletions

View File

@ -16,7 +16,7 @@ let config: IConfig = require('config')
// ---------------------------------------------------------------------------
const LAST_MIGRATION_VERSION = 270
const LAST_MIGRATION_VERSION = 275
// ---------------------------------------------------------------------------

View File

@ -0,0 +1,34 @@
import * as Sequelize from 'sequelize'
async function up (utils: {
transaction: Sequelize.Transaction
queryInterface: Sequelize.QueryInterface
sequelize: Sequelize.Sequelize
}): Promise<any> {
{
const query = 'DELETE FROM "videoFile" vf1 USING "videoFile" vf2 WHERE vf1.id < vf2.id ' +
'AND vf1."videoId" = vf2."videoId" AND vf1.resolution = vf2.resolution AND vf1.fps IS NULL'
await utils.sequelize.query(query)
}
{
const query = 'UPDATE "videoFile" SET fps = -1 WHERE fps IS NULL;'
await utils.sequelize.query(query)
}
{
const data = {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: -1
}
await utils.queryInterface.changeColumn('videoFile', 'fps', data)
}
}
function down (options) {
throw new Error('Not implemented.')
}
export { up, down }

View File

@ -478,7 +478,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje
resolution: fileUrl.height,
size: fileUrl.size,
videoId: videoCreated.id,
fps: fileUrl.fps
fps: fileUrl.fps || -1
} as VideoFileModel
attributes.push(attribute)
}

View File

@ -19,7 +19,6 @@ import { isAccountDescriptionValid } from '../../helpers/custom-validators/accou
import { sendDeleteActor } from '../../lib/activitypub/send'
import { ActorModel } from '../activitypub/actor'
import { ApplicationModel } from '../application/application'
import { AvatarModel } from '../avatar/avatar'
import { ServerModel } from '../server/server'
import { getSort, throwIfNotValid } from '../utils'
import { VideoChannelModel } from '../video/video-channel'

View File

@ -66,8 +66,8 @@ export class VideoFileModel extends Model<VideoFileModel> {
@Column
infoHash: string
@AllowNull(true)
@Default(null)
@AllowNull(false)
@Default(-1)
@Is('VideoFileFPS', value => throwIfNotValid(value, isVideoFPSResolutionValid, 'fps'))
@Column
fps: number