summary refs log tree commit diff
path: root/src/database/migration/postgres/1776450647000-GuildChannelOrderingAsArray.ts
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-06-11 23:18:02 +0200
committerRory& <root@rory.gay>2026-06-12 17:58:18 +0200
commit83e60464ad2675f09ddee02f6b166bef22f53f33 (patch)
tree9e12033c00c8420166f52c397b461cad288277fe /src/database/migration/postgres/1776450647000-GuildChannelOrderingAsArray.ts
parentFix recursive import in database (diff)
downloadserver-ts-83e60464ad2675f09ddee02f6b166bef22f53f33.tar.xz
Move migrations to database
Diffstat (limited to 'src/database/migration/postgres/1776450647000-GuildChannelOrderingAsArray.ts')
-rw-r--r--src/database/migration/postgres/1776450647000-GuildChannelOrderingAsArray.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/database/migration/postgres/1776450647000-GuildChannelOrderingAsArray.ts b/src/database/migration/postgres/1776450647000-GuildChannelOrderingAsArray.ts
new file mode 100644

index 00000000..e75c3e89 --- /dev/null +++ b/src/database/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`); + } +}