summary refs log tree commit diff
path: root/src/util/migration
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/migration')
-rw-r--r--src/util/migration/postgres/1776450647000-GuildChannelOrderingAsArray.ts17
-rw-r--r--src/util/migration/postgres/1776450647001-AllSimpleArraysToPgArrays.ts41
2 files changed, 58 insertions, 0 deletions
diff --git a/src/util/migration/postgres/1776450647000-GuildChannelOrderingAsArray.ts b/src/util/migration/postgres/1776450647000-GuildChannelOrderingAsArray.ts
new file mode 100644

index 00000000..e75c3e89 --- /dev/null +++ b/src/util/migration/postgres/1776450647000-GuildChannelOrderingAsArray.ts
@@ -0,0 +1,17 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class GuildChannelOrderingAsArray1776450647000 implements MigrationInterface { + name = "GuildChannelOrderingAsArray1776450647000"; + + public async up(queryRunner: QueryRunner): Promise<void> { + // spacebar was randomly adding json data into CSV values, unwrap them + await queryRunner.query(`UPDATE guilds SET channel_ordering = REPLACE(channel_ordering, '"', '') WHERE channel_ordering ~ '"';`); + await queryRunner.query(`UPDATE guilds SET channel_ordering = REPLACE(channel_ordering, '[', '') WHERE channel_ordering ~ '\\[';`); + await queryRunner.query(`UPDATE guilds SET channel_ordering = REPLACE(channel_ordering, ']', '') WHERE channel_ordering ~ '\\]';`); + await queryRunner.query(`ALTER TABLE guilds ALTER COLUMN channel_ordering TYPE int8[] USING string_to_array(channel_ordering, ',')::int8[];`); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + console.log(`Migration ${this.name}.down() not implemented`); + } +} diff --git a/src/util/migration/postgres/1776450647001-AllSimpleArraysToPgArrays.ts b/src/util/migration/postgres/1776450647001-AllSimpleArraysToPgArrays.ts new file mode 100644
index 00000000..44d2c591 --- /dev/null +++ b/src/util/migration/postgres/1776450647001-AllSimpleArraysToPgArrays.ts
@@ -0,0 +1,41 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AllSimpleArraysToPgArrays1776450647001 implements MigrationInterface { + name = "AllSimpleArraysToPgArrays1776450647001"; + + public async up(queryRunner: QueryRunner): Promise<void> { + await this.cleanAndConvertToArray(queryRunner, "applications", "redirect_uris", "varchar"); + await this.cleanAndConvertToArray(queryRunner, "applications", "tags", "varchar"); + // await this.cleanAndConvertToArray(queryRunner, "applications", "rpc_origins", "varchar"); + + await this.cleanAndConvertToArray(queryRunner, "automod_rules", "exempt_channels", "int8"); + await this.cleanAndConvertToArray(queryRunner, "automod_rules", "exempt_roles", "int8"); + + await this.cleanAndConvertToArray(queryRunner, "connected_accounts", "integrations", "varchar"); + + await this.cleanAndConvertToArray(queryRunner, "emojis", "roles", "int8"); + await this.cleanAndConvertToArray(queryRunner, "emojis", "groups", "int8"); + + await this.cleanAndConvertToArray(queryRunner, "guilds", "features", "varchar"); + + await this.cleanAndConvertToArray(queryRunner, "members", "theme_colors", "int4"); + + await this.cleanAndConvertToArray(queryRunner, "team_members", "permissions", "varchar"); + + await this.cleanAndConvertToArray(queryRunner, "users", "theme_colors", "int4"); + await this.cleanAndConvertToArray(queryRunner, "users", "fingerprints", "varchar"); + await this.cleanAndConvertToArray(queryRunner, "users", "badge_ids", "int8"); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + console.log(`Migration ${this.name}.down() not implemented`); + } + + private async cleanAndConvertToArray(queryRunner: QueryRunner, table: string, column: string, type: string) { + // spacebar was randomly adding json data into CSV values, unwrap them + await queryRunner.query(`UPDATE ${table} SET ${column} = REPLACE(${column}, '"', '') WHERE ${column} ~ '"';`); + await queryRunner.query(`UPDATE ${table} SET ${column} = REPLACE(${column}, '[', '') WHERE ${column} ~ '\\[';`); + await queryRunner.query(`UPDATE ${table} SET ${column} = REPLACE(${column}, ']', '') WHERE ${column} ~ '\\]';`); + await queryRunner.query(`ALTER TABLE ${table} ALTER COLUMN ${column} TYPE ${type}[] USING string_to_array(${column}, ',')::${type}[];`); + } +}