aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-11 16:01:56 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-11 16:01:56 +0200
commit0a6658fdcbd779ada8f3758048c326e997902d5a (patch)
tree5de40bf901db0299011104b1344783637b964eb0 /server/initializers/migrations
parente6d4b0ff2404dcf0b3a755c3fcc415ffeb6e754d (diff)
downloadPeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.tar.gz
PeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.tar.zst
PeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.zip
Use global uuid instead of remoteId for videos
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r--server/initializers/migrations/0005-email-pod.ts2
-rw-r--r--server/initializers/migrations/0010-email-user.ts2
-rw-r--r--server/initializers/migrations/0015-video-views.ts2
-rw-r--r--server/initializers/migrations/0020-video-likes.ts2
-rw-r--r--server/initializers/migrations/0025-video-dislikes.ts2
-rw-r--r--server/initializers/migrations/0030-video-category.ts2
-rw-r--r--server/initializers/migrations/0035-video-licence.ts2
-rw-r--r--server/initializers/migrations/0040-video-nsfw.ts2
-rw-r--r--server/initializers/migrations/0045-user-display-nsfw.ts2
-rw-r--r--server/initializers/migrations/0050-video-language.ts2
-rw-r--r--server/initializers/migrations/0055-video-uuid.ts157
11 files changed, 167 insertions, 10 deletions
diff --git a/server/initializers/migrations/0005-email-pod.ts b/server/initializers/migrations/0005-email-pod.ts
index ceefaad4a..ab60f3adb 100644
--- a/server/initializers/migrations/0005-email-pod.ts
+++ b/server/initializers/migrations/0005-email-pod.ts
@@ -26,7 +26,7 @@ function up (utils: {
26 }) 26 })
27} 27}
28 28
29function down (options, callback) { 29function down (options) {
30 throw new Error('Not implemented.') 30 throw new Error('Not implemented.')
31} 31}
32 32
diff --git a/server/initializers/migrations/0010-email-user.ts b/server/initializers/migrations/0010-email-user.ts
index e8865acdb..33d13ce55 100644
--- a/server/initializers/migrations/0010-email-user.ts
+++ b/server/initializers/migrations/0010-email-user.ts
@@ -25,7 +25,7 @@ function up (utils: {
25 }) 25 })
26} 26}
27 27
28function down (options, callback) { 28function down (options) {
29 throw new Error('Not implemented.') 29 throw new Error('Not implemented.')
30} 30}
31 31
diff --git a/server/initializers/migrations/0015-video-views.ts b/server/initializers/migrations/0015-video-views.ts
index df274d817..25164ff4d 100644
--- a/server/initializers/migrations/0015-video-views.ts
+++ b/server/initializers/migrations/0015-video-views.ts
@@ -17,7 +17,7 @@ function up (utils: {
17 return q.addColumn('Videos', 'views', data) 17 return q.addColumn('Videos', 'views', data)
18} 18}
19 19
20function down (options, callback) { 20function down (options) {
21 throw new Error('Not implemented.') 21 throw new Error('Not implemented.')
22} 22}
23 23
diff --git a/server/initializers/migrations/0020-video-likes.ts b/server/initializers/migrations/0020-video-likes.ts
index 3d7182d0a..945be5a98 100644
--- a/server/initializers/migrations/0020-video-likes.ts
+++ b/server/initializers/migrations/0020-video-likes.ts
@@ -17,7 +17,7 @@ function up (utils: {
17 return q.addColumn('Videos', 'likes', data) 17 return q.addColumn('Videos', 'likes', data)
18} 18}
19 19
20function down (options, callback) { 20function down (options) {
21 throw new Error('Not implemented.') 21 throw new Error('Not implemented.')
22} 22}
23 23
diff --git a/server/initializers/migrations/0025-video-dislikes.ts b/server/initializers/migrations/0025-video-dislikes.ts
index ed41095dc..27144c437 100644
--- a/server/initializers/migrations/0025-video-dislikes.ts
+++ b/server/initializers/migrations/0025-video-dislikes.ts
@@ -17,7 +17,7 @@ function up (utils: {
17 return q.addColumn('Videos', 'dislikes', data) 17 return q.addColumn('Videos', 'dislikes', data)
18} 18}
19 19
20function down (options, callback) { 20function down (options) {
21 throw new Error('Not implemented.') 21 throw new Error('Not implemented.')
22} 22}
23 23
diff --git a/server/initializers/migrations/0030-video-category.ts b/server/initializers/migrations/0030-video-category.ts
index f5adee8f9..41bc1aa98 100644
--- a/server/initializers/migrations/0030-video-category.ts
+++ b/server/initializers/migrations/0030-video-category.ts
@@ -22,7 +22,7 @@ function up (utils: {
22 }) 22 })
23} 23}
24 24
25function down (options, callback) { 25function down (options) {
26 throw new Error('Not implemented.') 26 throw new Error('Not implemented.')
27} 27}
28 28
diff --git a/server/initializers/migrations/0035-video-licence.ts b/server/initializers/migrations/0035-video-licence.ts
index 00c64d8e7..7ab49e147 100644
--- a/server/initializers/migrations/0035-video-licence.ts
+++ b/server/initializers/migrations/0035-video-licence.ts
@@ -21,7 +21,7 @@ function up (utils: {
21 }) 21 })
22} 22}
23 23
24function down (options, callback) { 24function down (options) {
25 throw new Error('Not implemented.') 25 throw new Error('Not implemented.')
26} 26}
27 27
diff --git a/server/initializers/migrations/0040-video-nsfw.ts b/server/initializers/migrations/0040-video-nsfw.ts
index 046876b61..0460e661d 100644
--- a/server/initializers/migrations/0040-video-nsfw.ts
+++ b/server/initializers/migrations/0040-video-nsfw.ts
@@ -22,7 +22,7 @@ function up (utils: {
22 }) 22 })
23} 23}
24 24
25function down (options, callback) { 25function down (options) {
26 throw new Error('Not implemented.') 26 throw new Error('Not implemented.')
27} 27}
28 28
diff --git a/server/initializers/migrations/0045-user-display-nsfw.ts b/server/initializers/migrations/0045-user-display-nsfw.ts
index 75bd3bbea..aef420f0e 100644
--- a/server/initializers/migrations/0045-user-display-nsfw.ts
+++ b/server/initializers/migrations/0045-user-display-nsfw.ts
@@ -17,7 +17,7 @@ function up (utils: {
17 return q.addColumn('Users', 'displayNSFW', data) 17 return q.addColumn('Users', 'displayNSFW', data)
18} 18}
19 19
20function down (options, callback) { 20function down (options) {
21 throw new Error('Not implemented.') 21 throw new Error('Not implemented.')
22} 22}
23 23
diff --git a/server/initializers/migrations/0050-video-language.ts b/server/initializers/migrations/0050-video-language.ts
index ed08f5866..796fa5f95 100644
--- a/server/initializers/migrations/0050-video-language.ts
+++ b/server/initializers/migrations/0050-video-language.ts
@@ -17,7 +17,7 @@ function up (utils: {
17 return q.addColumn('Videos', 'language', data) 17 return q.addColumn('Videos', 'language', data)
18} 18}
19 19
20function down (options, callback) { 20function down (options) {
21 throw new Error('Not implemented.') 21 throw new Error('Not implemented.')
22} 22}
23 23
diff --git a/server/initializers/migrations/0055-video-uuid.ts b/server/initializers/migrations/0055-video-uuid.ts
new file mode 100644
index 000000000..9bc65917c
--- /dev/null
+++ b/server/initializers/migrations/0055-video-uuid.ts
@@ -0,0 +1,157 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3
4function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize
8}): Promise<void> {
9 const q = utils.queryInterface
10
11 const dataUUID = {
12 type: Sequelize.UUID,
13 defaultValue: Sequelize.UUIDV4,
14 allowNull: true
15 }
16
17 return q.addColumn('Videos', 'uuid', dataUUID)
18 .then(() => {
19 const query = 'UPDATE "Videos" SET "uuid" = "id" WHERE "remoteId" IS NULL'
20 return utils.sequelize.query(query)
21 })
22 .then(() => {
23 const query = 'UPDATE "Videos" SET "uuid" = "remoteId" WHERE "remoteId" IS NOT NULL'
24 return utils.sequelize.query(query)
25 })
26 .then(() => {
27 dataUUID.defaultValue = null
28
29 return q.changeColumn('Videos', 'uuid', dataUUID)
30 })
31 .then(() => {
32 return removeForeignKey(utils.sequelize, 'RequestVideoQadus')
33 })
34 .then(() => {
35 return removeForeignKey(utils.sequelize, 'RequestVideoEvents')
36 })
37 .then(() => {
38 return removeForeignKey(utils.sequelize, 'BlacklistedVideos')
39 })
40 .then(() => {
41 return removeForeignKey(utils.sequelize, 'UserVideoRates')
42 })
43 .then(() => {
44 return removeForeignKey(utils.sequelize, 'VideoAbuses')
45 })
46 .then(() => {
47 return removeForeignKey(utils.sequelize, 'VideoTags')
48 })
49 .then(() => {
50 const query = 'ALTER TABLE "Videos" DROP CONSTRAINT "Videos_pkey"'
51 return utils.sequelize.query(query)
52 })
53 .then(() => {
54 const query = 'ALTER TABLE "Videos" ADD COLUMN "id2" SERIAL PRIMARY KEY'
55 return utils.sequelize.query(query)
56 })
57 .then(() => {
58 return q.renameColumn('Videos', 'id', 'oldId')
59 })
60 .then(() => {
61 return q.renameColumn('Videos', 'id2', 'id')
62 })
63 .then(() => {
64 return changeForeignKey(q, utils.sequelize, 'RequestVideoQadus', false)
65 })
66 .then(() => {
67 return changeForeignKey(q, utils.sequelize, 'RequestVideoEvents', false)
68 })
69 .then(() => {
70 return changeForeignKey(q, utils.sequelize, 'BlacklistedVideos', false)
71 })
72 .then(() => {
73 return changeForeignKey(q, utils.sequelize, 'UserVideoRates', false)
74 })
75 .then(() => {
76 return changeForeignKey(q, utils.sequelize, 'VideoAbuses', false)
77 })
78 .then(() => {
79 return changeForeignKey(q, utils.sequelize, 'VideoTags', true)
80 })
81 .then(() => {
82 return q.removeColumn('Videos', 'oldId')
83 })
84 .then(() => {
85 const dataRemote = {
86 type: Sequelize.BOOLEAN,
87 defaultValue: false,
88 allowNull: false
89 }
90 return q.addColumn('Videos', 'remote', dataRemote)
91 })
92 .then(() => {
93 const query = 'UPDATE "Videos" SET "remote" = false WHERE "remoteId" IS NULL'
94 return utils.sequelize.query(query)
95 })
96 .then(() => {
97 const query = 'UPDATE "Videos" SET "remote" = true WHERE "remoteId" IS NOT NULL'
98 return utils.sequelize.query(query)
99 })
100 .then(() => {
101 return q.removeColumn('Videos', 'remoteId')
102 })
103}
104
105function down (options) {
106 throw new Error('Not implemented.')
107}
108
109function removeForeignKey (sequelize: Sequelize.Sequelize, tableName: string) {
110 const query = 'ALTER TABLE "' + tableName + '" DROP CONSTRAINT "' + tableName + '_videoId_fkey' + '"'
111 return sequelize.query(query)
112}
113
114function changeForeignKey (q: Sequelize.QueryInterface, sequelize: Sequelize.Sequelize, tableName: string, allowNull: boolean) {
115 const data = {
116 type: Sequelize.INTEGER,
117 allowNull: true
118 }
119
120 return q.addColumn(tableName, 'videoId2', data)
121 .then(() => {
122 const query = 'UPDATE "' + tableName + '" SET "videoId2" = ' +
123 '(SELECT "id" FROM "Videos" WHERE "' + tableName + '"."videoId" = "Videos"."oldId")'
124 return sequelize.query(query)
125 })
126 .then(() => {
127 if (allowNull === false) {
128 data.allowNull = false
129
130 return q.changeColumn(tableName, 'videoId2', data)
131 }
132
133 return Promise.resolve()
134 })
135 .then(() => {
136 return q.removeColumn(tableName, 'videoId')
137 })
138 .then(() => {
139 return q.renameColumn(tableName, 'videoId2', 'videoId')
140 })
141 .then(() => {
142 return q.addIndex(tableName, [ 'videoId' ])
143 })
144 .then(() => {
145 const constraintName = tableName + '_videoId_fkey'
146 const query = 'ALTER TABLE "' + tableName + '" ' +
147 ' ADD CONSTRAINT "' + constraintName + '"' +
148 ' FOREIGN KEY ("videoId") REFERENCES "Videos" ON DELETE CASCADE'
149
150 return sequelize.query(query)
151 })
152}
153
154export {
155 up,
156 down
157}