From 083328eb27ec2b08a22a390363b11ae66869eba3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Apr 2021 14:45:40 +0200 Subject: Remove duplicate captions --- server/initializers/constants.ts | 2 +- .../migrations/0612-captions-unique.ts | 23 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 server/initializers/migrations/0612-captions-unique.ts diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 1623e6f42..50467f408 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -24,7 +24,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 610 +const LAST_MIGRATION_VERSION = 612 // --------------------------------------------------------------------------- diff --git a/server/initializers/migrations/0612-captions-unique.ts b/server/initializers/migrations/0612-captions-unique.ts new file mode 100644 index 000000000..368838a2a --- /dev/null +++ b/server/initializers/migrations/0612-captions-unique.ts @@ -0,0 +1,23 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize + db: any +}): Promise { + + await utils.sequelize.query( + 'DELETE FROM "videoCaption" v1 USING (SELECT MIN(id) as id, "filename" FROM "videoCaption" ' + + 'GROUP BY "filename" HAVING COUNT(*) > 1) v2 WHERE v1."filename" = v2."filename" AND v1.id <> v2.id' + ) +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3