diff options
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r-- | server/initializers/migrations/0525-abuse-messages.ts | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/server/initializers/migrations/0525-abuse-messages.ts b/server/initializers/migrations/0525-abuse-messages.ts new file mode 100644 index 000000000..c8fd7cbcf --- /dev/null +++ b/server/initializers/migrations/0525-abuse-messages.ts | |||
@@ -0,0 +1,54 @@ | |||
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 | }): Promise<void> { | ||
8 | await utils.sequelize.query(` | ||
9 | CREATE TABLE IF NOT EXISTS "abuseMessage" ( | ||
10 | "id" serial, | ||
11 | "message" text NOT NULL, | ||
12 | "byModerator" boolean NOT NULL, | ||
13 | "accountId" integer REFERENCES "account" ("id") ON DELETE SET NULL ON UPDATE CASCADE, | ||
14 | "abuseId" integer NOT NULL REFERENCES "abuse" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
15 | "createdAt" timestamp WITH time zone NOT NULL, | ||
16 | "updatedAt" timestamp WITH time zone NOT NULL, | ||
17 | PRIMARY KEY ("id") | ||
18 | ); | ||
19 | `) | ||
20 | |||
21 | const notificationSettingColumns = [ 'abuseStateChange', 'abuseNewMessage' ] | ||
22 | |||
23 | for (const column of notificationSettingColumns) { | ||
24 | const data = { | ||
25 | type: Sequelize.INTEGER, | ||
26 | defaultValue: null, | ||
27 | allowNull: true | ||
28 | } | ||
29 | await utils.queryInterface.addColumn('userNotificationSetting', column, data) | ||
30 | } | ||
31 | |||
32 | { | ||
33 | const query = 'UPDATE "userNotificationSetting" SET "abuseStateChange" = 3, "abuseNewMessage" = 3' | ||
34 | await utils.sequelize.query(query) | ||
35 | } | ||
36 | |||
37 | for (const column of notificationSettingColumns) { | ||
38 | const data = { | ||
39 | type: Sequelize.INTEGER, | ||
40 | defaultValue: null, | ||
41 | allowNull: false | ||
42 | } | ||
43 | await utils.queryInterface.changeColumn('userNotificationSetting', column, data) | ||
44 | } | ||
45 | } | ||
46 | |||
47 | function down (options) { | ||
48 | throw new Error('Not implemented.') | ||
49 | } | ||
50 | |||
51 | export { | ||
52 | up, | ||
53 | down | ||
54 | } | ||