aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-28 09:57:16 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-07-31 11:35:19 +0200
commitd573926e9b94fb19c8f51c53f71fc853182e1761 (patch)
tree907cc81c7275efe30aa90047c0763a7254bd1063 /server/initializers
parent594d3e48d8a887bbf48ce4cc594c1c36c9640fb1 (diff)
downloadPeerTube-d573926e9b94fb19c8f51c53f71fc853182e1761.tar.gz
PeerTube-d573926e9b94fb19c8f51c53f71fc853182e1761.tar.zst
PeerTube-d573926e9b94fb19c8f51c53f71fc853182e1761.zip
Add migrations for abuse messages
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/initializers/migrations/0525-abuse-messages.ts54
2 files changed, 55 insertions, 1 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index a40a22395..ca6c2a7ff 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -23,7 +23,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
23 23
24// --------------------------------------------------------------------------- 24// ---------------------------------------------------------------------------
25 25
26const LAST_MIGRATION_VERSION = 520 26const LAST_MIGRATION_VERSION = 525
27 27
28// --------------------------------------------------------------------------- 28// ---------------------------------------------------------------------------
29 29
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 @@
1import * as Sequelize from 'sequelize'
2
3async 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
47function down (options) {
48 throw new Error('Not implemented.')
49}
50
51export {
52 up,
53 down
54}