diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-15 14:08:16 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-02-16 10:36:44 +0100 |
commit | 6302d599cdf98b5a5363a2a1dcdc266447950191 (patch) | |
tree | b7dc6dc0f08f0fb8a20720242c9c0a71afeeaa3f /server/initializers/migrations | |
parent | a8b1b40485145ac1eae513a661d7dd6e0986ce96 (diff) | |
download | PeerTube-6302d599cdf98b5a5363a2a1dcdc266447950191.tar.gz PeerTube-6302d599cdf98b5a5363a2a1dcdc266447950191.tar.zst PeerTube-6302d599cdf98b5a5363a2a1dcdc266447950191.zip |
Generate a name for caption files
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r-- | server/initializers/migrations/0580-caption-filename.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/server/initializers/migrations/0580-caption-filename.ts b/server/initializers/migrations/0580-caption-filename.ts new file mode 100644 index 000000000..5281fd0c0 --- /dev/null +++ b/server/initializers/migrations/0580-caption-filename.ts | |||
@@ -0,0 +1,48 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | async function up (utils: { | ||
4 | transaction: Sequelize.Transaction | ||
5 | queryInterface: Sequelize.QueryInterface | ||
6 | sequelize: Sequelize.Sequelize | ||
7 | db: any | ||
8 | }): Promise<void> { | ||
9 | { | ||
10 | const data = { | ||
11 | type: Sequelize.STRING, | ||
12 | allowNull: true, | ||
13 | defaultValue: null | ||
14 | } | ||
15 | |||
16 | await utils.queryInterface.addColumn('videoCaption', 'filename', data) | ||
17 | } | ||
18 | |||
19 | { | ||
20 | const query = `UPDATE "videoCaption" SET "filename" = s.uuid || '-' || s.language || '.vtt' ` + | ||
21 | `FROM (` + | ||
22 | ` SELECT "videoCaption"."id", video.uuid, "videoCaption".language ` + | ||
23 | ` FROM "videoCaption" INNER JOIN video ON video.id = "videoCaption"."videoId"` + | ||
24 | `) AS s ` + | ||
25 | `WHERE "videoCaption".id = s.id` | ||
26 | |||
27 | await utils.sequelize.query(query) | ||
28 | } | ||
29 | |||
30 | { | ||
31 | const data = { | ||
32 | type: Sequelize.STRING, | ||
33 | allowNull: false, | ||
34 | defaultValue: null | ||
35 | } | ||
36 | |||
37 | await utils.queryInterface.changeColumn('videoCaption', 'filename', data) | ||
38 | } | ||
39 | } | ||
40 | |||
41 | function down (options) { | ||
42 | throw new Error('Not implemented.') | ||
43 | } | ||
44 | |||
45 | export { | ||
46 | up, | ||
47 | down | ||
48 | } | ||