summary refs log tree commit diff
path: root/src/util/migrations/sqlite/1661885742207-guild-member-profiles.ts
blob: 24ec9c7279c686f1b963926e8eb39678532e7183 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { MigrationInterface, QueryRunner } from "typeorm";

export class guildMemberProfiles1661885742207 implements MigrationInterface {
    name = 'guildMemberProfiles1661885742207'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`
            DROP INDEX "IDX_bb2bf9386ac443afbbbf9f12d3"
        `);
        await queryRunner.query(`
            CREATE TABLE "temporary_members" (
                "index" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
                "id" varchar NOT NULL,
                "guild_id" varchar NOT NULL,
                "nick" varchar,
                "joined_at" datetime NOT NULL,
                "premium_since" datetime,
                "deaf" boolean NOT NULL,
                "mute" boolean NOT NULL,
                "pending" boolean NOT NULL,
                "settings" text NOT NULL,
                "last_message_id" varchar,
                "joined_by" varchar,
                "avatar" varchar,
                "banner" varchar,
                "bio" varchar NOT NULL,
                "communication_disabled_until" datetime,
                CONSTRAINT "FK_28b53062261b996d9c99fa12404" FOREIGN KEY ("id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
                CONSTRAINT "FK_16aceddd5b89825b8ed6029ad1c" FOREIGN KEY ("guild_id") REFERENCES "guilds" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
            )
        `);
        await queryRunner.query(`
            INSERT INTO "temporary_members"(
                    "index",
                    "id",
                    "guild_id",
                    "nick",
                    "joined_at",
                    "premium_since",
                    "deaf",
                    "mute",
                    "pending",
                    "settings",
                    "last_message_id",
                    "joined_by"
                )
            SELECT "index",
                "id",
                "guild_id",
                "nick",
                "joined_at",
                "premium_since",
                "deaf",
                "mute",
                "pending",
                "settings",
                "last_message_id",
                "joined_by"
            FROM "members"
        `);
        await queryRunner.query(`
            DROP TABLE "members"
        `);
        await queryRunner.query(`
            ALTER TABLE "temporary_members"
                RENAME TO "members"
        `);
        await queryRunner.query(`
            CREATE UNIQUE INDEX "IDX_bb2bf9386ac443afbbbf9f12d3" ON "members" ("id", "guild_id")
        `);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`
            DROP INDEX "IDX_bb2bf9386ac443afbbbf9f12d3"
        `);
        await queryRunner.query(`
            ALTER TABLE "members"
                RENAME TO "temporary_members"
        `);
        await queryRunner.query(`
            CREATE TABLE "members" (
                "index" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
                "id" varchar NOT NULL,
                "guild_id" varchar NOT NULL,
                "nick" varchar,
                "joined_at" datetime NOT NULL,
                "premium_since" datetime,
                "deaf" boolean NOT NULL,
                "mute" boolean NOT NULL,
                "pending" boolean NOT NULL,
                "settings" text NOT NULL,
                "last_message_id" varchar,
                "joined_by" varchar,
                CONSTRAINT "FK_28b53062261b996d9c99fa12404" FOREIGN KEY ("id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
                CONSTRAINT "FK_16aceddd5b89825b8ed6029ad1c" FOREIGN KEY ("guild_id") REFERENCES "guilds" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
            )
        `);
        await queryRunner.query(`
            INSERT INTO "members"(
                    "index",
                    "id",
                    "guild_id",
                    "nick",
                    "joined_at",
                    "premium_since",
                    "deaf",
                    "mute",
                    "pending",
                    "settings",
                    "last_message_id",
                    "joined_by"
                )
            SELECT "index",
                "id",
                "guild_id",
                "nick",
                "joined_at",
                "premium_since",
                "deaf",
                "mute",
                "pending",
                "settings",
                "last_message_id",
                "joined_by"
            FROM "temporary_members"
        `);
        await queryRunner.query(`
            DROP TABLE "temporary_members"
        `);
        await queryRunner.query(`
            CREATE UNIQUE INDEX "IDX_bb2bf9386ac443afbbbf9f12d3" ON "members" ("id", "guild_id")
        `);
    }

}