summary refs log tree commit diff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/src/entities/BaseClass.ts2
-rw-r--r--util/src/entities/Channel.ts7
-rw-r--r--util/src/entities/User.ts6
-rw-r--r--util/src/migrations/mariadb/1660265930624-CodeCleanup5.ts53
-rw-r--r--util/src/migrations/postgres/1660265907544-CodeCleanup5.ts26
-rw-r--r--util/src/migrations/sqlite/1660260539853-CodeCleanup4.ts459
6 files changed, 91 insertions, 462 deletions
diff --git a/util/src/entities/BaseClass.ts b/util/src/entities/BaseClass.ts
index c872e7f1..aecc2465 100644
--- a/util/src/entities/BaseClass.ts
+++ b/util/src/entities/BaseClass.ts
@@ -1,5 +1,5 @@
 import "reflect-metadata";
-import { BaseEntity, EntityMetadata, ObjectIdColumn, PrimaryColumn, FindOptionsWhere, Generated, SaveOptions } from "typeorm";
+import { BaseEntity, ObjectIdColumn, PrimaryColumn, SaveOptions } from "typeorm";
 import { Snowflake } from "../util/Snowflake";
 
 export class BaseClassWithoutId extends BaseEntity {
diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts
index ade0fb39..a576d7af 100644
--- a/util/src/entities/Channel.ts
+++ b/util/src/entities/Channel.ts
@@ -151,6 +151,13 @@ export class Channel extends BaseClass {
 	})

 	webhooks?: Webhook[];

 

+	@Column({ nullable: true })

+	flags?: number = 0;

+	

+	@Column({ nullable: true })

+	default_thread_rate_limit_per_user?: number = 0;

+

+

 	// TODO: DM channel

 	static async createChannel(

 		channel: Partial<Channel>,

diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts
index 6edcda97..61343e81 100644
--- a/util/src/entities/User.ts
+++ b/util/src/entities/User.ts
@@ -185,8 +185,10 @@ export class User extends BaseClass {
 	notes: { [key: string]: string } = {}; //key is ID of user
 
 	async save(): Promise<any> {
-		await this.settings.save();
-		return this.save();
+		if(!this.settings) this.settings = new UserSettings();
+		this.settings.id = this.id;
+		//await this.settings.save();
+		return super.save();
 	}
 
 	toPublicUser() {
diff --git a/util/src/migrations/mariadb/1660265930624-CodeCleanup5.ts b/util/src/migrations/mariadb/1660265930624-CodeCleanup5.ts
new file mode 100644
index 00000000..04f8e6af
--- /dev/null
+++ b/util/src/migrations/mariadb/1660265930624-CodeCleanup5.ts
@@ -0,0 +1,53 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class CodeCleanup51660265930624 implements MigrationInterface {
+    name = 'CodeCleanup51660265930624'
+
+    public async up(queryRunner: QueryRunner): Promise<void> {
+        await queryRunner.query(`
+            ALTER TABLE \`users\`
+            ADD \`settingsId\` varchar(255) NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`users\`
+            ADD UNIQUE INDEX \`IDX_76ba283779c8441fd5ff819c8c\` (\`settingsId\`)
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`channels\`
+            ADD \`flags\` int NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`channels\`
+            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
+        `);
+    }
+
+    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\`
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`channels\` DROP COLUMN \`default_thread_rate_limit_per_user\`
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`channels\` DROP COLUMN \`flags\`
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`users\` DROP INDEX \`IDX_76ba283779c8441fd5ff819c8c\`
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`users\` DROP COLUMN \`settingsId\`
+        `);
+    }
+
+}
diff --git a/util/src/migrations/postgres/1660265907544-CodeCleanup5.ts b/util/src/migrations/postgres/1660265907544-CodeCleanup5.ts
new file mode 100644
index 00000000..157d686a
--- /dev/null
+++ b/util/src/migrations/postgres/1660265907544-CodeCleanup5.ts
@@ -0,0 +1,26 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class CodeCleanup51660265907544 implements MigrationInterface {
+    name = 'CodeCleanup51660265907544'
+
+    public async up(queryRunner: QueryRunner): Promise<void> {
+        await queryRunner.query(`
+            ALTER TABLE "channels"
+            ADD "flags" integer
+        `);
+        await queryRunner.query(`
+            ALTER TABLE "channels"
+            ADD "default_thread_rate_limit_per_user" integer
+        `);
+    }
+
+    public async down(queryRunner: QueryRunner): Promise<void> {
+        await queryRunner.query(`
+            ALTER TABLE "channels" DROP COLUMN "default_thread_rate_limit_per_user"
+        `);
+        await queryRunner.query(`
+            ALTER TABLE "channels" DROP COLUMN "flags"
+        `);
+    }
+
+}
diff --git a/util/src/migrations/sqlite/1660260539853-CodeCleanup4.ts b/util/src/migrations/sqlite/1660260539853-CodeCleanup4.ts
deleted file mode 100644
index d3f2a40d..00000000
--- a/util/src/migrations/sqlite/1660260539853-CodeCleanup4.ts
+++ /dev/null
@@ -1,459 +0,0 @@
-import { MigrationInterface, QueryRunner } from "typeorm";
-
-export class CodeCleanup41660260539853 implements MigrationInterface {
-    name = 'CodeCleanup41660260539853'
-
-    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 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")
-            )
-        `);
-        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"
-                )
-            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"
-            FROM "users"
-        `);
-        await queryRunner.query(`
-            DROP TABLE "users"
-        `);
-        await queryRunner.query(`
-            ALTER TABLE "temporary_users"
-                RENAME TO "users"
-        `);
-        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 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 "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")
-            )
-        `);
-        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"
-        `);
-        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
-            )
-        `);
-        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"
-                )
-            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"
-            FROM "temporary_users"
-        `);
-        await queryRunner.query(`
-            DROP TABLE "temporary_users"
-        `);
-    }
-
-}