aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0750-user-registration.ts
blob: 15bbfd3fd0782f69a41d106d94b901c3a068b846 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import * as Sequelize from 'sequelize'

async function up (utils: {
  transaction: Sequelize.Transaction
  queryInterface: Sequelize.QueryInterface
  sequelize: Sequelize.Sequelize
  db: any
}): Promise<void> {
  {
    const query = `
      CREATE TABLE IF NOT EXISTS "userRegistration" (
        "id" serial,
        "state" integer NOT NULL,
        "registrationReason" text NOT NULL,
        "moderationResponse" text,
        "password" varchar(255),
        "username" varchar(255) NOT NULL,
        "email" varchar(400) NOT NULL,
        "emailVerified" boolean,
        "accountDisplayName" varchar(255),
        "channelHandle" varchar(255),
        "channelDisplayName" varchar(255),
        "userId" integer REFERENCES "user" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
        "createdAt" timestamp with time zone NOT NULL,
        "updatedAt" timestamp with time zone NOT NULL,
        PRIMARY KEY ("id")
      );
    `
    await utils.sequelize.query(query, { transaction: utils.transaction })
  }

  {
    await utils.queryInterface.addColumn('userNotification', 'userRegistrationId', {
      type: Sequelize.INTEGER,
      defaultValue: null,
      allowNull: true,
      references: {
        model: 'userRegistration',
        key: 'id'
      },
      onUpdate: 'CASCADE',
      onDelete: 'SET NULL'
    }, { transaction: utils.transaction })
  }
}

async function down (utils: {
  queryInterface: Sequelize.QueryInterface
  transaction: Sequelize.Transaction
}) {
  await utils.queryInterface.dropTable('videoChannelSync', { transaction: utils.transaction })
}

export {
  up,
  down
}