aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-19 08:41:32 +0100
committerChocobozzz <me@florianbigard.com>2021-02-19 08:41:32 +0100
commite33933e44c82c02792372efe9590c9b8a3a495a0 (patch)
tree7b2e2b0ec3a7fca80c2c1a2f0b7725ad68f2cfbe /server/initializers
parent6d22ea006b606f6d604727a277384525b0335a95 (diff)
downloadPeerTube-e33933e44c82c02792372efe9590c9b8a3a495a0.tar.gz
PeerTube-e33933e44c82c02792372efe9590c9b8a3a495a0.tar.zst
PeerTube-e33933e44c82c02792372efe9590c9b8a3a495a0.zip
Fix latest migrations
We made an historical mistake: we have a unique key on videoId, resolution AND fps. But the filenames and torrent filenames do not have fps in their name Remove these duplicate entries
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/initializers/migrations/0600-duplicate-video-files.ts33
2 files changed, 34 insertions, 1 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index fbedc2164..f0123e87c 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -24,7 +24,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
24 24
25// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
26 26
27const LAST_MIGRATION_VERSION = 595 27const LAST_MIGRATION_VERSION = 600
28 28
29// --------------------------------------------------------------------------- 29// ---------------------------------------------------------------------------
30 30
diff --git a/server/initializers/migrations/0600-duplicate-video-files.ts b/server/initializers/migrations/0600-duplicate-video-files.ts
new file mode 100644
index 000000000..92d774a79
--- /dev/null
+++ b/server/initializers/migrations/0600-duplicate-video-files.ts
@@ -0,0 +1,33 @@
1import * as Sequelize from 'sequelize'
2
3async function up (utils: {
4 transaction: Sequelize.Transaction
5 queryInterface: Sequelize.QueryInterface
6 sequelize: Sequelize.Sequelize
7 db: any
8}): Promise<void> {
9
10 {
11 const query = 'DELETE FROM "videoFile" f1 ' +
12 'USING (SELECT MIN(id) as id, "torrentFilename" FROM "videoFile" GROUP BY "torrentFilename" HAVING COUNT(*) > 1) f2 ' +
13 'WHERE f1."torrentFilename" = f2."torrentFilename" AND f1.id <> f2.id'
14 await utils.sequelize.query(query)
15 }
16
17 {
18 const query = 'DELETE FROM "videoFile" f1 ' +
19 'USING (SELECT MIN(id) as id, "filename" FROM "videoFile" GROUP BY "filename" HAVING COUNT(*) > 1) f2 ' +
20 'WHERE f1."filename" = f2."filename" AND f1.id <> f2.id'
21 await utils.sequelize.query(query)
22 }
23
24}
25
26function down (options) {
27 throw new Error('Not implemented.')
28}
29
30export {
31 up,
32 down
33}