From 2e7cf5ae0cf8fbc9526742b67a0079d42211644c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 26 Sep 2018 14:08:35 +0200 Subject: Fix video files duplicated when fps is null Null values are not considered equal in a UNIQUE index --- .../migrations/0260-upload-quota-daily.ts | 23 +++++++++++++++ .../migrations/0260-upload_quota_daily.ts | 23 --------------- .../migrations/0275-video-file-unique.ts | 34 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 server/initializers/migrations/0260-upload-quota-daily.ts delete mode 100644 server/initializers/migrations/0260-upload_quota_daily.ts create mode 100644 server/initializers/migrations/0275-video-file-unique.ts (limited to 'server/initializers/migrations') diff --git a/server/initializers/migrations/0260-upload-quota-daily.ts b/server/initializers/migrations/0260-upload-quota-daily.ts new file mode 100644 index 000000000..d25154ba6 --- /dev/null +++ b/server/initializers/migrations/0260-upload-quota-daily.ts @@ -0,0 +1,23 @@ +import * as Sequelize from 'sequelize' +import { CONSTRAINTS_FIELDS } from '../constants' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize +}): Promise { + { + const data = { + type: Sequelize.BIGINT, + allowNull: false, + defaultValue: -1 + } + await utils.queryInterface.addColumn('user', 'videoQuotaDaily', data) + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { up, down } diff --git a/server/initializers/migrations/0260-upload_quota_daily.ts b/server/initializers/migrations/0260-upload_quota_daily.ts deleted file mode 100644 index d25154ba6..000000000 --- a/server/initializers/migrations/0260-upload_quota_daily.ts +++ /dev/null @@ -1,23 +0,0 @@ -import * as Sequelize from 'sequelize' -import { CONSTRAINTS_FIELDS } from '../constants' - -async function up (utils: { - transaction: Sequelize.Transaction - queryInterface: Sequelize.QueryInterface - sequelize: Sequelize.Sequelize -}): Promise { - { - const data = { - type: Sequelize.BIGINT, - allowNull: false, - defaultValue: -1 - } - await utils.queryInterface.addColumn('user', 'videoQuotaDaily', data) - } -} - -function down (options) { - throw new Error('Not implemented.') -} - -export { up, down } diff --git a/server/initializers/migrations/0275-video-file-unique.ts b/server/initializers/migrations/0275-video-file-unique.ts new file mode 100644 index 000000000..fd89188c0 --- /dev/null +++ b/server/initializers/migrations/0275-video-file-unique.ts @@ -0,0 +1,34 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize +}): Promise { + { + 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 } -- cgit v1.2.3