mirror of https://github.com/Chocobozzz/PeerTube
Fix video files duplicated when fps is null
Null values are not considered equal in a UNIQUE indexpull/1104/merge
parent
60e74f80d8
commit
2e7cf5ae0c
|
@ -16,7 +16,7 @@ let config: IConfig = require('config')
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const LAST_MIGRATION_VERSION = 270
|
||||
const LAST_MIGRATION_VERSION = 275
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -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 }
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue