]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/migrations/0600-duplicate-video-files.ts
server: serve files from storage/well-known (#5214)
[github/Chocobozzz/PeerTube.git] / server / initializers / migrations / 0600-duplicate-video-files.ts
1 import * as Sequelize from 'sequelize'
2
3 async 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
26 function down (options) {
27 throw new Error('Not implemented.')
28 }
29
30 export {
31 up,
32 down
33 }