]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/migrations/0420-avatar-lazy.ts
predefined report reasons & improved reporter UI (#2842)
[github/Chocobozzz/PeerTube.git] / server / initializers / migrations / 0420-avatar-lazy.ts
CommitLineData
557b13ae
C
1import * as Sequelize from 'sequelize'
2
3async function up (utils: {
a1587156
C
4 transaction: Sequelize.Transaction
5 queryInterface: Sequelize.QueryInterface
6 sequelize: Sequelize.Sequelize
557b13ae
C
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
53function down (options) {
54 throw new Error('Not implemented.')
55}
56
57export {
58 up,
59 down
60}