summary refs log tree commit diff
path: root/src/util/migrations/sqlite/1660538628956-sync_migrations.ts
blob: 9cdc064fb3e7c83ece421e28c33ce64062df059c (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
import { MigrationInterface, QueryRunner } from "typeorm";

export class syncMigrations1660538628956 implements MigrationInterface {
    name = 'syncMigrations1660538628956'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`
            CREATE TABLE "temporary_channels" (
                "id" varchar PRIMARY KEY NOT NULL,
                "created_at" datetime NOT NULL,
                "name" varchar,
                "icon" text,
                "type" integer NOT NULL,
                "last_message_id" varchar,
                "guild_id" varchar,
                "parent_id" varchar,
                "owner_id" varchar,
                "last_pin_timestamp" integer,
                "default_auto_archive_duration" integer,
                "position" integer,
                "permission_overwrites" text,
                "video_quality_mode" integer,
                "bitrate" integer,
                "user_limit" integer,
                "nsfw" boolean,
                "rate_limit_per_user" integer,
                "topic" varchar,
                "retention_policy_id" varchar,
                "flags" integer,
                "default_thread_rate_limit_per_user" integer,
                CONSTRAINT "FK_3873ed438575cce703ecff4fc7b" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION,
                CONSTRAINT "FK_3274522d14af40540b1a883fc80" FOREIGN KEY ("parent_id") REFERENCES "channels" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION,
                CONSTRAINT "FK_c253dafe5f3a03ec00cd8fb4581" FOREIGN KEY ("guild_id") REFERENCES "guilds" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
            )
        `);
        await queryRunner.query(`
            INSERT INTO "temporary_channels"(
                    "id",
                    "created_at",
                    "name",
                    "icon",
                    "type",
                    "last_message_id",
                    "guild_id",
                    "parent_id",
                    "owner_id",
                    "last_pin_timestamp",
                    "default_auto_archive_duration",
                    "position",
                    "permission_overwrites",
                    "video_quality_mode",
                    "bitrate",
                    "user_limit",
                    "nsfw",
                    "rate_limit_per_user",
                    "topic",
                    "retention_policy_id"
                )
            SELECT "id",
                "created_at",
                "name",
                "icon",
                "type",
                "last_message_id",
                "guild_id",
                "parent_id",
                "owner_id",
                "last_pin_timestamp",
                "default_auto_archive_duration",
                "position",
                "permission_overwrites",
                "video_quality_mode",
                "bitrate",
                "user_limit",
                "nsfw",
                "rate_limit_per_user",
                "topic",
                "retention_policy_id"
            FROM "channels"
        `);
        await queryRunner.query(`
            DROP TABLE "channels"
        `);
        await queryRunner.query(`
            ALTER TABLE "temporary_channels"
                RENAME TO "channels"
        `);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`
            ALTER TABLE "channels"
                RENAME TO "temporary_channels"
        `);
        await queryRunner.query(`
            CREATE TABLE "channels" (
                "id" varchar PRIMARY KEY NOT NULL,
                "created_at" datetime NOT NULL,
                "name" varchar,
                "icon" text,
                "type" integer NOT NULL,
                "last_message_id" varchar,
                "guild_id" varchar,
                "parent_id" varchar,
                "owner_id" varchar,
                "last_pin_timestamp" integer,
                "default_auto_archive_duration" integer,
                "position" integer,
                "permission_overwrites" text,
                "video_quality_mode" integer,
                "bitrate" integer,
                "user_limit" integer,
                "nsfw" boolean,
                "rate_limit_per_user" integer,
                "topic" varchar,
                "retention_policy_id" varchar,
                CONSTRAINT "FK_3873ed438575cce703ecff4fc7b" FOREIGN KEY ("owner_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION,
                CONSTRAINT "FK_3274522d14af40540b1a883fc80" FOREIGN KEY ("parent_id") REFERENCES "channels" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION,
                CONSTRAINT "FK_c253dafe5f3a03ec00cd8fb4581" FOREIGN KEY ("guild_id") REFERENCES "guilds" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
            )
        `);
        await queryRunner.query(`
            INSERT INTO "channels"(
                    "id",
                    "created_at",
                    "name",
                    "icon",
                    "type",
                    "last_message_id",
                    "guild_id",
                    "parent_id",
                    "owner_id",
                    "last_pin_timestamp",
                    "default_auto_archive_duration",
                    "position",
                    "permission_overwrites",
                    "video_quality_mode",
                    "bitrate",
                    "user_limit",
                    "nsfw",
                    "rate_limit_per_user",
                    "topic",
                    "retention_policy_id"
                )
            SELECT "id",
                "created_at",
                "name",
                "icon",
                "type",
                "last_message_id",
                "guild_id",
                "parent_id",
                "owner_id",
                "last_pin_timestamp",
                "default_auto_archive_duration",
                "position",
                "permission_overwrites",
                "video_quality_mode",
                "bitrate",
                "user_limit",
                "nsfw",
                "rate_limit_per_user",
                "topic",
                "retention_policy_id"
            FROM "temporary_channels"
        `);
        await queryRunner.query(`
            DROP TABLE "temporary_channels"
        `);
    }

}