diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2022-08-13 20:43:35 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2022-08-15 06:13:39 +0200 |
commit | 5e629decfc5aaa58fb5c584fa15e76fd5b44c23f (patch) | |
tree | 98dbb29a1a4b8c15c0eb4c57be1610c54192dce9 | |
parent | downgrade ajv so patches apply (diff) | |
download | server-5e629decfc5aaa58fb5c584fa15e76fd5b44c23f.tar.xz |
Do the funny thing (make user->invite cascade delet)
-rw-r--r-- | src/util/migrations/mariadb/1660416072362-InvitersAreDeletable.ts (renamed from src/util/migrations/mariadb/1660265930624-CodeCleanup5.ts) | 37 | ||||
-rw-r--r-- | src/util/migrations/postgres/1660416055566-InvitersAreDeletable.ts | 26 | ||||
-rw-r--r-- | src/util/migrations/sqlite/1660416010862-InvitersAreDeletable.ts | 246 |
3 files changed, 292 insertions, 17 deletions
diff --git a/src/util/migrations/mariadb/1660265930624-CodeCleanup5.ts b/src/util/migrations/mariadb/1660416072362-InvitersAreDeletable.ts index 04f8e6af..8374eafb 100644 --- a/src/util/migrations/mariadb/1660265930624-CodeCleanup5.ts +++ b/src/util/migrations/mariadb/1660416072362-InvitersAreDeletable.ts @@ -1,16 +1,21 @@ import { MigrationInterface, QueryRunner } from "typeorm"; -export class CodeCleanup51660265930624 implements MigrationInterface { - name = 'CodeCleanup51660265930624' +export class InvitersAreDeletable1660416072362 implements MigrationInterface { + name = 'InvitersAreDeletable1660416072362' public async up(queryRunner: QueryRunner): Promise<void> { await queryRunner.query(` - ALTER TABLE \`users\` - ADD \`settingsId\` varchar(255) NULL + ALTER TABLE \`invites\` DROP FOREIGN KEY \`FK_15c35422032e0b22b4ada95f48f\` `); await queryRunner.query(` - ALTER TABLE \`users\` - ADD UNIQUE INDEX \`IDX_76ba283779c8441fd5ff819c8c\` (\`settingsId\`) + DROP INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\` + `); + await queryRunner.query(` + CREATE TABLE \`plugin_config\` ( + \`key\` varchar(255) NOT NULL, + \`value\` text NULL, + PRIMARY KEY (\`key\`) + ) ENGINE = InnoDB `); await queryRunner.query(` ALTER TABLE \`channels\` @@ -21,20 +26,14 @@ export class CodeCleanup51660265930624 implements MigrationInterface { ADD \`default_thread_rate_limit_per_user\` int NULL `); await queryRunner.query(` - CREATE UNIQUE INDEX \`REL_76ba283779c8441fd5ff819c8c\` ON \`users\` (\`settingsId\`) - `); - await queryRunner.query(` - ALTER TABLE \`users\` - ADD CONSTRAINT \`FK_76ba283779c8441fd5ff819c8cf\` FOREIGN KEY (\`settingsId\`) REFERENCES \`user_settings\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION + ALTER TABLE \`invites\` + ADD CONSTRAINT \`FK_15c35422032e0b22b4ada95f48f\` FOREIGN KEY (\`inviter_id\`) REFERENCES \`users\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION `); } public async down(queryRunner: QueryRunner): Promise<void> { await queryRunner.query(` - ALTER TABLE \`users\` DROP FOREIGN KEY \`FK_76ba283779c8441fd5ff819c8cf\` - `); - await queryRunner.query(` - DROP INDEX \`REL_76ba283779c8441fd5ff819c8c\` ON \`users\` + ALTER TABLE \`invites\` DROP FOREIGN KEY \`FK_15c35422032e0b22b4ada95f48f\` `); await queryRunner.query(` ALTER TABLE \`channels\` DROP COLUMN \`default_thread_rate_limit_per_user\` @@ -43,10 +42,14 @@ export class CodeCleanup51660265930624 implements MigrationInterface { ALTER TABLE \`channels\` DROP COLUMN \`flags\` `); await queryRunner.query(` - ALTER TABLE \`users\` DROP INDEX \`IDX_76ba283779c8441fd5ff819c8c\` + DROP TABLE \`plugin_config\` + `); + await queryRunner.query(` + CREATE UNIQUE INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\` (\`settingsId\`) `); await queryRunner.query(` - ALTER TABLE \`users\` DROP COLUMN \`settingsId\` + ALTER TABLE \`invites\` + ADD CONSTRAINT \`FK_15c35422032e0b22b4ada95f48f\` FOREIGN KEY (\`inviter_id\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION `); } diff --git a/src/util/migrations/postgres/1660416055566-InvitersAreDeletable.ts b/src/util/migrations/postgres/1660416055566-InvitersAreDeletable.ts new file mode 100644 index 00000000..e6101318 --- /dev/null +++ b/src/util/migrations/postgres/1660416055566-InvitersAreDeletable.ts @@ -0,0 +1,26 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class InvitersAreDeletable1660416055566 implements MigrationInterface { + name = 'InvitersAreDeletable1660416055566' + + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` + ALTER TABLE "invites" DROP CONSTRAINT "FK_15c35422032e0b22b4ada95f48f" + `); + await queryRunner.query(` + ALTER TABLE "invites" + ADD CONSTRAINT "FK_15c35422032e0b22b4ada95f48f" FOREIGN KEY ("inviter_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE NO ACTION + `); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` + ALTER TABLE "invites" DROP CONSTRAINT "FK_15c35422032e0b22b4ada95f48f" + `); + await queryRunner.query(` + ALTER TABLE "invites" + ADD CONSTRAINT "FK_15c35422032e0b22b4ada95f48f" FOREIGN KEY ("inviter_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION + `); + } + +} diff --git a/src/util/migrations/sqlite/1660416010862-InvitersAreDeletable.ts b/src/util/migrations/sqlite/1660416010862-InvitersAreDeletable.ts new file mode 100644 index 00000000..9b29e119 --- /dev/null +++ b/src/util/migrations/sqlite/1660416010862-InvitersAreDeletable.ts @@ -0,0 +1,246 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class InvitersAreDeletable1660416010862 implements MigrationInterface { + name = 'InvitersAreDeletable1660416010862' + + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` + CREATE TABLE "temporary_invites" ( + "code" varchar PRIMARY KEY NOT NULL, + "temporary" boolean NOT NULL, + "uses" integer NOT NULL, + "max_uses" integer NOT NULL, + "max_age" integer NOT NULL, + "created_at" datetime NOT NULL, + "expires_at" datetime NOT NULL, + "guild_id" varchar, + "channel_id" varchar, + "inviter_id" varchar, + "target_user_id" varchar, + "target_user_type" integer, + "vanity_url" boolean, + CONSTRAINT "FK_11a0d394f8fc649c19ce5f16b59" FOREIGN KEY ("target_user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT "FK_6a15b051fe5050aa00a4b9ff0f6" FOREIGN KEY ("channel_id") REFERENCES "channels" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT "FK_3f4939aa1461e8af57fea3fb05d" FOREIGN KEY ("guild_id") REFERENCES "guilds" ("id") ON DELETE CASCADE ON UPDATE NO ACTION + ) + `); + await queryRunner.query(` + INSERT INTO "temporary_invites"( + "code", + "temporary", + "uses", + "max_uses", + "max_age", + "created_at", + "expires_at", + "guild_id", + "channel_id", + "inviter_id", + "target_user_id", + "target_user_type", + "vanity_url" + ) + SELECT "code", + "temporary", + "uses", + "max_uses", + "max_age", + "created_at", + "expires_at", + "guild_id", + "channel_id", + "inviter_id", + "target_user_id", + "target_user_type", + "vanity_url" + FROM "invites" + `); + await queryRunner.query(` + DROP TABLE "invites" + `); + await queryRunner.query(` + ALTER TABLE "temporary_invites" + RENAME TO "invites" + `); + await queryRunner.query(` + CREATE TABLE "temporary_invites" ( + "code" varchar PRIMARY KEY NOT NULL, + "temporary" boolean NOT NULL, + "uses" integer NOT NULL, + "max_uses" integer NOT NULL, + "max_age" integer NOT NULL, + "created_at" datetime NOT NULL, + "expires_at" datetime NOT NULL, + "guild_id" varchar, + "channel_id" varchar, + "inviter_id" varchar, + "target_user_id" varchar, + "target_user_type" integer, + "vanity_url" boolean, + CONSTRAINT "FK_11a0d394f8fc649c19ce5f16b59" FOREIGN KEY ("target_user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT "FK_6a15b051fe5050aa00a4b9ff0f6" FOREIGN KEY ("channel_id") REFERENCES "channels" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT "FK_3f4939aa1461e8af57fea3fb05d" FOREIGN KEY ("guild_id") REFERENCES "guilds" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT "FK_15c35422032e0b22b4ada95f48f" FOREIGN KEY ("inviter_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION + ) + `); + await queryRunner.query(` + INSERT INTO "temporary_invites"( + "code", + "temporary", + "uses", + "max_uses", + "max_age", + "created_at", + "expires_at", + "guild_id", + "channel_id", + "inviter_id", + "target_user_id", + "target_user_type", + "vanity_url" + ) + SELECT "code", + "temporary", + "uses", + "max_uses", + "max_age", + "created_at", + "expires_at", + "guild_id", + "channel_id", + "inviter_id", + "target_user_id", + "target_user_type", + "vanity_url" + FROM "invites" + `); + await queryRunner.query(` + DROP TABLE "invites" + `); + await queryRunner.query(` + ALTER TABLE "temporary_invites" + RENAME TO "invites" + `); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` + ALTER TABLE "invites" + RENAME TO "temporary_invites" + `); + await queryRunner.query(` + CREATE TABLE "invites" ( + "code" varchar PRIMARY KEY NOT NULL, + "temporary" boolean NOT NULL, + "uses" integer NOT NULL, + "max_uses" integer NOT NULL, + "max_age" integer NOT NULL, + "created_at" datetime NOT NULL, + "expires_at" datetime NOT NULL, + "guild_id" varchar, + "channel_id" varchar, + "inviter_id" varchar, + "target_user_id" varchar, + "target_user_type" integer, + "vanity_url" boolean, + CONSTRAINT "FK_11a0d394f8fc649c19ce5f16b59" FOREIGN KEY ("target_user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT "FK_6a15b051fe5050aa00a4b9ff0f6" FOREIGN KEY ("channel_id") REFERENCES "channels" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT "FK_3f4939aa1461e8af57fea3fb05d" FOREIGN KEY ("guild_id") REFERENCES "guilds" ("id") ON DELETE CASCADE ON UPDATE NO ACTION + ) + `); + await queryRunner.query(` + INSERT INTO "invites"( + "code", + "temporary", + "uses", + "max_uses", + "max_age", + "created_at", + "expires_at", + "guild_id", + "channel_id", + "inviter_id", + "target_user_id", + "target_user_type", + "vanity_url" + ) + SELECT "code", + "temporary", + "uses", + "max_uses", + "max_age", + "created_at", + "expires_at", + "guild_id", + "channel_id", + "inviter_id", + "target_user_id", + "target_user_type", + "vanity_url" + FROM "temporary_invites" + `); + await queryRunner.query(` + DROP TABLE "temporary_invites" + `); + await queryRunner.query(` + ALTER TABLE "invites" + RENAME TO "temporary_invites" + `); + await queryRunner.query(` + CREATE TABLE "invites" ( + "code" varchar PRIMARY KEY NOT NULL, + "temporary" boolean NOT NULL, + "uses" integer NOT NULL, + "max_uses" integer NOT NULL, + "max_age" integer NOT NULL, + "created_at" datetime NOT NULL, + "expires_at" datetime NOT NULL, + "guild_id" varchar, + "channel_id" varchar, + "inviter_id" varchar, + "target_user_id" varchar, + "target_user_type" integer, + "vanity_url" boolean, + CONSTRAINT "FK_11a0d394f8fc649c19ce5f16b59" FOREIGN KEY ("target_user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT "FK_15c35422032e0b22b4ada95f48f" FOREIGN KEY ("inviter_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT "FK_6a15b051fe5050aa00a4b9ff0f6" FOREIGN KEY ("channel_id") REFERENCES "channels" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT "FK_3f4939aa1461e8af57fea3fb05d" FOREIGN KEY ("guild_id") REFERENCES "guilds" ("id") ON DELETE CASCADE ON UPDATE NO ACTION + ) + `); + await queryRunner.query(` + INSERT INTO "invites"( + "code", + "temporary", + "uses", + "max_uses", + "max_age", + "created_at", + "expires_at", + "guild_id", + "channel_id", + "inviter_id", + "target_user_id", + "target_user_type", + "vanity_url" + ) + SELECT "code", + "temporary", + "uses", + "max_uses", + "max_age", + "created_at", + "expires_at", + "guild_id", + "channel_id", + "inviter_id", + "target_user_id", + "target_user_type", + "vanity_url" + FROM "temporary_invites" + `); + await queryRunner.query(` + DROP TABLE "temporary_invites" + `); + } + +} |