aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0345-video-playlists.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-21 14:54:29 +0100
committerChocobozzz <me@florianbigard.com>2022-03-21 14:54:29 +0100
commit348c2ce3ff3fe2f25a31f08bfb36c88723a0ce46 (patch)
tree972ec51091bab14e7671ef7db3b6e43ea5f116f7 /server/initializers/migrations/0345-video-playlists.ts
parente6afb669402aead6bf3d9d7ba4f2bd434c831eab (diff)
downloadPeerTube-348c2ce3ff3fe2f25a31f08bfb36c88723a0ce46.tar.gz
PeerTube-348c2ce3ff3fe2f25a31f08bfb36c88723a0ce46.tar.zst
PeerTube-348c2ce3ff3fe2f25a31f08bfb36c88723a0ce46.zip
Remove old migration files
Diffstat (limited to 'server/initializers/migrations/0345-video-playlists.ts')
-rw-r--r--server/initializers/migrations/0345-video-playlists.ts88
1 files changed, 0 insertions, 88 deletions
diff --git a/server/initializers/migrations/0345-video-playlists.ts b/server/initializers/migrations/0345-video-playlists.ts
deleted file mode 100644
index 4bf3100e4..000000000
--- a/server/initializers/migrations/0345-video-playlists.ts
+++ /dev/null
@@ -1,88 +0,0 @@
1import * as Sequelize from 'sequelize'
2import { buildUUID } from '@shared/extra-utils'
3import { VideoPlaylistPrivacy, VideoPlaylistType } from '../../../shared/models/videos'
4import { WEBSERVER } from '../constants'
5
6async function up (utils: {
7 transaction: Sequelize.Transaction
8 queryInterface: Sequelize.QueryInterface
9 sequelize: Sequelize.Sequelize
10}): Promise<void> {
11 const transaction = utils.transaction
12
13 {
14 const query = `
15CREATE TABLE IF NOT EXISTS "videoPlaylist"
16(
17 "id" SERIAL,
18 "name" VARCHAR(255) NOT NULL,
19 "description" VARCHAR(255),
20 "privacy" INTEGER NOT NULL,
21 "url" VARCHAR(2000) NOT NULL,
22 "uuid" UUID NOT NULL,
23 "type" INTEGER NOT NULL DEFAULT 1,
24 "ownerAccountId" INTEGER NOT NULL REFERENCES "account" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
25 "videoChannelId" INTEGER REFERENCES "videoChannel" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
26 "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL,
27 "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL,
28 PRIMARY KEY ("id")
29);`
30 await utils.sequelize.query(query, { transaction })
31 }
32
33 {
34 const query = `
35CREATE TABLE IF NOT EXISTS "videoPlaylistElement"
36(
37 "id" SERIAL,
38 "url" VARCHAR(2000) NOT NULL,
39 "position" INTEGER NOT NULL DEFAULT 1,
40 "startTimestamp" INTEGER,
41 "stopTimestamp" INTEGER,
42 "videoPlaylistId" INTEGER NOT NULL REFERENCES "videoPlaylist" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
43 "videoId" INTEGER NOT NULL REFERENCES "video" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
44 "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL,
45 "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL,
46 PRIMARY KEY ("id")
47);`
48
49 await utils.sequelize.query(query, { transaction })
50 }
51
52 {
53 const userQuery = 'SELECT "username" FROM "user";'
54
55 const options = { transaction, type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT }
56 const userResult = await utils.sequelize.query<{ username: string }>(userQuery, options)
57 const usernames = userResult.map(r => r.username)
58
59 for (const username of usernames) {
60 const uuid = buildUUID()
61
62 const baseUrl = WEBSERVER.URL + '/video-playlists/' + uuid
63 const query = `
64 INSERT INTO "videoPlaylist" ("url", "uuid", "name", "privacy", "type", "ownerAccountId", "createdAt", "updatedAt")
65 SELECT '${baseUrl}' AS "url",
66 '${uuid}' AS "uuid",
67 'Watch later' AS "name",
68 ${VideoPlaylistPrivacy.PRIVATE} AS "privacy",
69 ${VideoPlaylistType.WATCH_LATER} AS "type",
70 "account"."id" AS "ownerAccountId",
71 NOW() as "createdAt",
72 NOW() as "updatedAt"
73 FROM "user" INNER JOIN "account" ON "user"."id" = "account"."userId"
74 WHERE "user"."username" = '${username}'`
75
76 await utils.sequelize.query(query, { transaction })
77 }
78 }
79}
80
81function down (options) {
82 throw new Error('Not implemented.')
83}
84
85export {
86 up,
87 down
88}