aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0305-fix-unfederated-videos.ts
blob: 9c5d56b7bd6a58329b1c2d328c2960d11aae7ffe (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
48
49
50
51
52
import * as Sequelize from 'sequelize'

async function up (utils: {
  transaction: Sequelize.Transaction
  queryInterface: Sequelize.QueryInterface
  sequelize: Sequelize.Sequelize
  db: any
}): Promise<void> {
  {
    const query = `INSERT INTO "videoShare" (url, "actorId", "videoId", "createdAt", "updatedAt") ` +
      `(` +
        `SELECT ` +
        `video.url || '/announces/' || "videoChannel"."actorId" as url, ` +
        `"videoChannel"."actorId" AS "actorId", ` +
        `"video"."id" AS "videoId", ` +
        `NOW() AS "createdAt", ` +
        `NOW() AS "updatedAt" ` +
        `FROM video ` +
        `INNER JOIN "videoChannel" ON "video"."channelId" = "videoChannel"."id" ` +
        `WHERE "video"."remote" = false AND "video"."privacy" != 3 AND "video"."state" = 1` +
      `) ` +
      `ON CONFLICT DO NOTHING`

    await utils.sequelize.query(query)
  }

  {
    const query = `INSERT INTO "videoShare" (url, "actorId", "videoId", "createdAt", "updatedAt") ` +
      `(` +
        `SELECT ` +
        `video.url || '/announces/' || (SELECT id FROM actor WHERE "preferredUsername" = 'peertube' ORDER BY id ASC LIMIT 1) as url, ` +
        `(SELECT id FROM actor WHERE "preferredUsername" = 'peertube' ORDER BY id ASC LIMIT 1) AS "actorId", ` +
        `"video"."id" AS "videoId", ` +
        `NOW() AS "createdAt", ` +
        `NOW() AS "updatedAt" ` +
        `FROM video ` +
        `WHERE "video"."remote" = false AND "video"."privacy" != 3 AND "video"."state" = 1` +
      `) ` +
      `ON CONFLICT DO NOTHING`

    await utils.sequelize.query(query)
  }
}

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

export {
  up,
  down
}