diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-09 11:32:40 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-09 11:32:40 +0200 |
commit | 557b13ae24019d9ab214bbea7eaa0f892c8f4b05 (patch) | |
tree | aa32396531acf93e3dfdb29880177813039ed77f /server/initializers/migrations | |
parent | c5407d7046168abb4098df1408e7aa84519cb61a (diff) | |
download | PeerTube-557b13ae24019d9ab214bbea7eaa0f892c8f4b05.tar.gz PeerTube-557b13ae24019d9ab214bbea7eaa0f892c8f4b05.tar.zst PeerTube-557b13ae24019d9ab214bbea7eaa0f892c8f4b05.zip |
Lazy load avatars
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r-- | server/initializers/migrations/0420-avatar-lazy.ts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/server/initializers/migrations/0420-avatar-lazy.ts b/server/initializers/migrations/0420-avatar-lazy.ts new file mode 100644 index 000000000..5fc57aac2 --- /dev/null +++ b/server/initializers/migrations/0420-avatar-lazy.ts | |||
@@ -0,0 +1,60 @@ | |||
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 | // We'll add a unique index on filename, so delete duplicates or PeerTube won't start | ||
11 | const query = 'DELETE FROM "avatar" s1 ' + | ||
12 | 'USING (SELECT MIN(id) as id, filename FROM "avatar" GROUP BY "filename" HAVING COUNT(*) > 1) s2 ' + | ||
13 | 'WHERE s1."filename" = s2."filename" AND s1.id <> s2.id' | ||
14 | await utils.sequelize.query(query) | ||
15 | } | ||
16 | |||
17 | { | ||
18 | const data = { | ||
19 | type: Sequelize.STRING, | ||
20 | allowNull: true, | ||
21 | defaultValue: null | ||
22 | } | ||
23 | |||
24 | await utils.queryInterface.addColumn('avatar', 'fileUrl', data) | ||
25 | } | ||
26 | |||
27 | { | ||
28 | const data = { | ||
29 | type: Sequelize.BOOLEAN, | ||
30 | allowNull: true, | ||
31 | defaultValue: null | ||
32 | } | ||
33 | |||
34 | await utils.queryInterface.addColumn('avatar', 'onDisk', data) | ||
35 | } | ||
36 | |||
37 | { | ||
38 | const query = 'UPDATE "avatar" SET "onDisk" = true;' | ||
39 | await utils.sequelize.query(query) | ||
40 | } | ||
41 | |||
42 | { | ||
43 | const data = { | ||
44 | type: Sequelize.BOOLEAN, | ||
45 | allowNull: false, | ||
46 | defaultValue: null | ||
47 | } | ||
48 | |||
49 | await utils.queryInterface.changeColumn('avatar', 'onDisk', data) | ||
50 | } | ||
51 | } | ||
52 | |||
53 | function down (options) { | ||
54 | throw new Error('Not implemented.') | ||
55 | } | ||
56 | |||
57 | export { | ||
58 | up, | ||
59 | down | ||
60 | } | ||