aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0235-delete-some-video-indexes.ts
blob: e362f240c3e4aa431afce50165e8beb6ef7e5309 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as Sequelize from 'sequelize'
import { createClient } from 'redis'
import { CONFIG } from '../constants'
import { JobQueue } from '../../lib/job-queue'
import { initDatabaseModels } from '../database'

async function up (utils: {
  transaction: Sequelize.Transaction
  queryInterface: Sequelize.QueryInterface
  sequelize: Sequelize.Sequelize
}): Promise<any> {
  await utils.sequelize.query('DROP INDEX IF EXISTS video_id_privacy_state_wait_transcoding;')
  await utils.sequelize.query('DROP INDEX IF EXISTS video_name;')

  for (let i = 0; i < 5; i++) {
    const query = 'DELETE FROM "videoFile" WHERE id IN ' +
      '(SELECT id FROM (SELECT MIN(id) AS id, "videoId", "resolution", "fps" ' +
      'FROM "videoFile" GROUP BY "videoId", "resolution", "fps" HAVING COUNT(*) > 1) t)'
    await utils.sequelize.query(query)
  }

  for (let i = 0; i < 5; i++) {
    const query = 'DELETE FROM "actor" WHERE id IN ' +
      '(SELECT id FROM (SELECT MIN(id) AS id, "uuid" ' +
      'FROM "actor" GROUP BY "uuid" HAVING COUNT(*) > 1) t)'
    await utils.sequelize.query(query)
  }

  for (let i = 0; i < 5; i++) {
    const query = 'DELETE FROM "account" WHERE id IN ' +
      '(SELECT id FROM (SELECT MIN(id) AS id, "actorId" ' +
      'FROM "account" GROUP BY "actorId" HAVING COUNT(*) > 1) t)'
    await utils.sequelize.query(query)
  }
}

function down (options) {
  throw new Error('Not implemented.')
}

export { up, down }