summary refs log tree commit diff
path: root/src/util/migrations/sqlite/1660549233583-fix_nullables.ts
blob: fa60bdc166f74e3b9afffb68be1a2f64d7d38802 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import { MigrationInterface, QueryRunner } from "typeorm";

export class fixNullables1660549233583 implements MigrationInterface {
	name = "fixNullables1660549233583";

	public async up(queryRunner: QueryRunner): Promise<void> {
		await queryRunner.query(`
            CREATE TABLE "temporary_users" (
                "id" varchar PRIMARY KEY NOT NULL,
                "username" varchar NOT NULL,
                "discriminator" varchar NOT NULL,
                "avatar" varchar,
                "accent_color" integer,
                "banner" varchar,
                "phone" varchar,
                "desktop" boolean NOT NULL,
                "mobile" boolean NOT NULL,
                "premium" boolean NOT NULL,
                "premium_type" integer NOT NULL,
                "bot" boolean NOT NULL,
                "bio" varchar,
                "system" boolean NOT NULL,
                "nsfw_allowed" boolean NOT NULL,
                "mfa_enabled" boolean,
                "totp_secret" varchar,
                "totp_last_ticket" varchar,
                "created_at" datetime NOT NULL,
                "premium_since" datetime,
                "verified" boolean NOT NULL,
                "disabled" boolean NOT NULL,
                "deleted" boolean NOT NULL,
                "email" varchar,
                "flags" varchar NOT NULL,
                "public_flags" integer NOT NULL,
                "rights" bigint NOT NULL,
                "data" text NOT NULL,
                "fingerprints" text NOT NULL,
                "extended_settings" text NOT NULL,
                "notes" text NOT NULL,
                "settingsId" varchar,
                CONSTRAINT "UQ_b1dd13b6ed980004a795ca184a6" UNIQUE ("settingsId"),
                CONSTRAINT "FK_76ba283779c8441fd5ff819c8cf" FOREIGN KEY ("settingsId") REFERENCES "user_settings" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
            )
        `);
		await queryRunner.query(`
            INSERT INTO "temporary_users"(
                    "id",
                    "username",
                    "discriminator",
                    "avatar",
                    "accent_color",
                    "banner",
                    "phone",
                    "desktop",
                    "mobile",
                    "premium",
                    "premium_type",
                    "bot",
                    "bio",
                    "system",
                    "nsfw_allowed",
                    "mfa_enabled",
                    "totp_secret",
                    "totp_last_ticket",
                    "created_at",
                    "premium_since",
                    "verified",
                    "disabled",
                    "deleted",
                    "email",
                    "flags",
                    "public_flags",
                    "rights",
                    "data",
                    "fingerprints",
                    "extended_settings",
                    "notes",
                    "settingsId"
                )
            SELECT "id",
                "username",
                "discriminator",
                "avatar",
                "accent_color",
                "banner",
                "phone",
                "desktop",
                "mobile",
                "premium",
                "premium_type",
                "bot",
                "bio",
                "system",
                "nsfw_allowed",
                "mfa_enabled",
                "totp_secret",
                "totp_last_ticket",
                "created_at",
                "premium_since",
                "verified",
                "disabled",
                "deleted",
                "email",
                "flags",
                "public_flags",
                "rights",
                "data",
                "fingerprints",
                "extended_settings",
                "notes",
                "settingsId"
            FROM "users"
        `);
		await queryRunner.query(`
            DROP TABLE "users"
        `);
		await queryRunner.query(`
            ALTER TABLE "temporary_users"
                RENAME TO "users"
        `);
	}

	public async down(queryRunner: QueryRunner): Promise<void> {
		await queryRunner.query(`
            ALTER TABLE "users"
                RENAME TO "temporary_users"
        `);
		await queryRunner.query(`
            CREATE TABLE "users" (
                "id" varchar PRIMARY KEY NOT NULL,
                "username" varchar NOT NULL,
                "discriminator" varchar NOT NULL,
                "avatar" varchar,
                "accent_color" integer,
                "banner" varchar,
                "phone" varchar,
                "desktop" boolean NOT NULL,
                "mobile" boolean NOT NULL,
                "premium" boolean NOT NULL,
                "premium_type" integer NOT NULL,
                "bot" boolean NOT NULL,
                "bio" varchar NOT NULL,
                "system" boolean NOT NULL,
                "nsfw_allowed" boolean NOT NULL,
                "mfa_enabled" boolean NOT NULL,
                "totp_secret" varchar,
                "totp_last_ticket" varchar,
                "created_at" datetime NOT NULL,
                "premium_since" datetime,
                "verified" boolean NOT NULL,
                "disabled" boolean NOT NULL,
                "deleted" boolean NOT NULL,
                "email" varchar,
                "flags" varchar NOT NULL,
                "public_flags" integer NOT NULL,
                "rights" bigint NOT NULL,
                "data" text NOT NULL,
                "fingerprints" text NOT NULL,
                "extended_settings" text NOT NULL,
                "notes" text NOT NULL,
                "settingsId" varchar,
                CONSTRAINT "UQ_b1dd13b6ed980004a795ca184a6" UNIQUE ("settingsId"),
                CONSTRAINT "FK_76ba283779c8441fd5ff819c8cf" FOREIGN KEY ("settingsId") REFERENCES "user_settings" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
            )
        `);
		await queryRunner.query(`
            INSERT INTO "users"(
                    "id",
                    "username",
                    "discriminator",
                    "avatar",
                    "accent_color",
                    "banner",
                    "phone",
                    "desktop",
                    "mobile",
                    "premium",
                    "premium_type",
                    "bot",
                    "bio",
                    "system",
                    "nsfw_allowed",
                    "mfa_enabled",
                    "totp_secret",
                    "totp_last_ticket",
                    "created_at",
                    "premium_since",
                    "verified",
                    "disabled",
                    "deleted",
                    "email",
                    "flags",
                    "public_flags",
                    "rights",
                    "data",
                    "fingerprints",
                    "extended_settings",
                    "notes",
                    "settingsId"
                )
            SELECT "id",
                "username",
                "discriminator",
                "avatar",
                "accent_color",
                "banner",
                "phone",
                "desktop",
                "mobile",
                "premium",
                "premium_type",
                "bot",
                "bio",
                "system",
                "nsfw_allowed",
                "mfa_enabled",
                "totp_secret",
                "totp_last_ticket",
                "created_at",
                "premium_since",
                "verified",
                "disabled",
                "deleted",
                "email",
                "flags",
                "public_flags",
                "rights",
                "data",
                "fingerprints",
                "extended_settings",
                "notes",
                "settingsId"
            FROM "temporary_users"
        `);
		await queryRunner.query(`
            DROP TABLE "temporary_users"
        `);
	}
}