From f008e9f3f34ed1724afd5e071c39ed931741acbc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Jan 2023 11:56:04 +0100 Subject: Add missing url unique index in local video viewer --- .../migrations/0755-unique-viewer-url.ts | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 server/initializers/migrations/0755-unique-viewer-url.ts (limited to 'server/initializers/migrations/0755-unique-viewer-url.ts') diff --git a/server/initializers/migrations/0755-unique-viewer-url.ts b/server/initializers/migrations/0755-unique-viewer-url.ts new file mode 100644 index 000000000..b3dff9258 --- /dev/null +++ b/server/initializers/migrations/0755-unique-viewer-url.ts @@ -0,0 +1,27 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize + db: any +}): Promise { + const { transaction } = utils + + const query = 'DELETE FROM "localVideoViewer" t1 ' + + 'USING (SELECT MIN(id) as id, "url" FROM "localVideoViewer" GROUP BY "url" HAVING COUNT(*) > 1) t2 ' + + 'WHERE t1."url" = t2."url" AND t1.id <> t2.id' + + await utils.sequelize.query(query, { transaction }) +} + +async function down (utils: { + queryInterface: Sequelize.QueryInterface + transaction: Sequelize.Transaction +}) { +} + +export { + up, + down +} -- cgit v1.2.3