aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0790-thumbnail-disk.ts
blob: 0824c042e0751bfd6f2e9da8d961a904b6d7d6df (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
42
43
44
45
46
47
import * as Sequelize from 'sequelize'

async function up (utils: {
  transaction: Sequelize.Transaction
  queryInterface: Sequelize.QueryInterface
  sequelize: Sequelize.Sequelize
}): Promise<void> {
  const { transaction } = utils

  {
    const data = {
      type: Sequelize.BOOLEAN,
      allowNull: true,
      defaultValue: true
    }

    await utils.queryInterface.addColumn('thumbnail', 'onDisk', data, { transaction })
  }

  {
    // Remote previews are not on the disk
    await utils.sequelize.query(
      'UPDATE "thumbnail" SET "onDisk" = FALSE ' +
      'WHERE "type" = 2 AND "videoId" NOT IN (SELECT "id" FROM "video" WHERE "remote" IS FALSE)',
      { transaction }
    )
  }

  {
    const data = {
      type: Sequelize.BOOLEAN,
      allowNull: false,
      defaultValue: null
    }

    await utils.queryInterface.changeColumn('thumbnail', 'onDisk', data, { transaction })
  }
}

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

export {
  up,
  down
}