diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-11 16:01:56 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-11 16:01:56 +0200 |
commit | 0a6658fdcbd779ada8f3758048c326e997902d5a (patch) | |
tree | 5de40bf901db0299011104b1344783637b964eb0 /server/initializers | |
parent | e6d4b0ff2404dcf0b3a755c3fcc415ffeb6e754d (diff) | |
download | PeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.tar.gz PeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.tar.zst PeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.zip |
Use global uuid instead of remoteId for videos
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0005-email-pod.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0010-email-user.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0015-video-views.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0020-video-likes.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0025-video-dislikes.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0030-video-category.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0035-video-licence.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0040-video-nsfw.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0045-user-display-nsfw.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0050-video-language.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0055-video-uuid.ts | 157 | ||||
-rw-r--r-- | server/initializers/migrator.ts | 4 |
13 files changed, 170 insertions, 13 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 2792d3228..f087b7476 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -15,7 +15,7 @@ import { | |||
15 | 15 | ||
16 | // --------------------------------------------------------------------------- | 16 | // --------------------------------------------------------------------------- |
17 | 17 | ||
18 | const LAST_MIGRATION_VERSION = 50 | 18 | const LAST_MIGRATION_VERSION = 55 |
19 | 19 | ||
20 | // --------------------------------------------------------------------------- | 20 | // --------------------------------------------------------------------------- |
21 | 21 | ||
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 | ||
29 | function down (options, callback) { | 29 | function 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 | ||
28 | function down (options, callback) { | 28 | function 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 | ||
20 | function down (options, callback) { | 20 | function 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 | ||
20 | function down (options, callback) { | 20 | function 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 | ||
20 | function down (options, callback) { | 20 | function 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 | ||
25 | function down (options, callback) { | 25 | function 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 | ||
24 | function down (options, callback) { | 24 | function 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 | ||
25 | function down (options, callback) { | 25 | function 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 | ||
20 | function down (options, callback) { | 20 | function 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 | ||
20 | function down (options, callback) { | 20 | function 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 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import * as Promise from 'bluebird' | ||
3 | |||
4 | function 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 | |||
105 | function down (options) { | ||
106 | throw new Error('Not implemented.') | ||
107 | } | ||
108 | |||
109 | function removeForeignKey (sequelize: Sequelize.Sequelize, tableName: string) { | ||
110 | const query = 'ALTER TABLE "' + tableName + '" DROP CONSTRAINT "' + tableName + '_videoId_fkey' + '"' | ||
111 | return sequelize.query(query) | ||
112 | } | ||
113 | |||
114 | function 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 | |||
154 | export { | ||
155 | up, | ||
156 | down | ||
157 | } | ||
diff --git a/server/initializers/migrator.ts b/server/initializers/migrator.ts index 3184ec920..4b3be6d16 100644 --- a/server/initializers/migrator.ts +++ b/server/initializers/migrator.ts | |||
@@ -96,10 +96,10 @@ function executeMigration (actualVersion: number, entity: { version: string, scr | |||
96 | sequelize: db.sequelize | 96 | sequelize: db.sequelize |
97 | } | 97 | } |
98 | 98 | ||
99 | migrationScript.up(options) | 99 | return migrationScript.up(options) |
100 | .then(() => { | 100 | .then(() => { |
101 | // Update the new migration version | 101 | // Update the new migration version |
102 | db.Application.updateMigrationVersion(versionScript, t) | 102 | return db.Application.updateMigrationVersion(versionScript, t) |
103 | }) | 103 | }) |
104 | }) | 104 | }) |
105 | } | 105 | } |