summary refs log tree commit diff
path: root/util/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-10 14:09:54 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-10 14:09:54 +0200
commit2f623b2a2276321b74c4601f67f5236be2ae5243 (patch)
treee115399283f6572b3e80b5fc5b01cb0554f6d96d /util/src
parent:bug: fix cdn route not working without hash (diff)
downloadserver-2f623b2a2276321b74c4601f67f5236be2ae5243.tar.xz
:art: emoji db migration
Diffstat (limited to 'util/src')
-rw-r--r--util/src/entities/Emoji.ts14
-rw-r--r--util/src/interfaces/Event.ts8
-rw-r--r--util/src/migrations/1633864260873-EmojiRoles.ts13
-rw-r--r--util/src/migrations/1633864669243-EmojiUser.ts23
4 files changed, 53 insertions, 5 deletions
diff --git a/util/src/entities/Emoji.ts b/util/src/entities/Emoji.ts
index a252d9f4..03218375 100644
--- a/util/src/entities/Emoji.ts
+++ b/util/src/entities/Emoji.ts
@@ -1,4 +1,5 @@
-import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
+import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
+import { User } from ".";
 import { BaseClass } from "./BaseClass";
 import { Guild } from "./Guild";
 import { Role } from "./Role";
@@ -20,6 +21,14 @@ export class Emoji extends BaseClass {
 	})
 	guild: Guild;
 
+	@Column({ nullable: true })
+	@RelationId((emoji: Emoji) => emoji.user)
+	user_id: string;
+
+	@JoinColumn({ name: "user_id" })
+	@ManyToOne(() => User)
+	user: User;
+
 	@Column()
 	managed: boolean;
 
@@ -28,4 +37,7 @@ export class Emoji extends BaseClass {
 
 	@Column()
 	require_colons: boolean;
+
+	@Column({ type: "simple-array" })
+	roles: string[]; // roles this emoji is whitelisted to (new discord feature?)
 }
diff --git a/util/src/interfaces/Event.ts b/util/src/interfaces/Event.ts
index 03099bbb..3c8ab8ab 100644
--- a/util/src/interfaces/Event.ts
+++ b/util/src/interfaces/Event.ts
@@ -185,8 +185,8 @@ export interface GuildBanRemoveEvent extends Event {
 	};
 }
 
-export interface GuildEmojiUpdateEvent extends Event {
-	event: "GUILD_EMOJI_UPDATE";
+export interface GuildEmojisUpdateEvent extends Event {
+	event: "GUILD_EMOJIS_UPDATE";
 	data: {
 		guild_id: string;
 		emojis: Emoji[];
@@ -459,7 +459,7 @@ export type EventData =
 	| GuildDeleteEvent
 	| GuildBanAddEvent
 	| GuildBanRemoveEvent
-	| GuildEmojiUpdateEvent
+	| GuildEmojisUpdateEvent
 	| GuildIntegrationUpdateEvent
 	| GuildMemberAddEvent
 	| GuildMemberRemoveEvent
@@ -552,7 +552,7 @@ export type EVENT =
 	| "GUILD_DELETE"
 	| "GUILD_BAN_ADD"
 	| "GUILD_BAN_REMOVE"
-	| "GUILD_EMOJI_UPDATE"
+	| "GUILD_EMOJIS_UPDATE"
 	| "GUILD_INTEGRATIONS_UPDATE"
 	| "GUILD_MEMBER_ADD"
 	| "GUILD_MEMBER_REMOVE"
diff --git a/util/src/migrations/1633864260873-EmojiRoles.ts b/util/src/migrations/1633864260873-EmojiRoles.ts
new file mode 100644
index 00000000..f0d709f2
--- /dev/null
+++ b/util/src/migrations/1633864260873-EmojiRoles.ts
@@ -0,0 +1,13 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class EmojiRoles1633864260873 implements MigrationInterface {
+	name = "EmojiRoles1633864260873";
+
+	public async up(queryRunner: QueryRunner): Promise<void> {
+		await queryRunner.query(`ALTER TABLE "emojis" ADD "roles" text NOT NULL DEFAULT ''`);
+	}
+
+	public async down(queryRunner: QueryRunner): Promise<void> {
+		await queryRunner.query(`ALTER TABLE "emojis" DROP COLUMN column_name "roles"`);
+	}
+}
diff --git a/util/src/migrations/1633864669243-EmojiUser.ts b/util/src/migrations/1633864669243-EmojiUser.ts
new file mode 100644
index 00000000..982405d7
--- /dev/null
+++ b/util/src/migrations/1633864669243-EmojiUser.ts
@@ -0,0 +1,23 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class EmojiUser1633864669243 implements MigrationInterface {
+	name = "EmojiUser1633864669243";
+
+	public async up(queryRunner: QueryRunner): Promise<void> {
+		await queryRunner.query(`ALTER TABLE "emojis" ADD "user_id" varchar`);
+		try {
+			await queryRunner.query(
+				`ALTER TABLE "emojis" ADD CONSTRAINT FK_fa7ddd5f9a214e28ce596548421 FOREIGN KEY (user_id) REFERENCES users(id)`
+			);
+		} catch (error) {
+			console.error(
+				"sqlite doesn't support altering foreign keys: https://stackoverflow.com/questions/1884818/how-do-i-add-a-foreign-key-to-an-existing-sqlite-table"
+			);
+		}
+	}
+
+	public async down(queryRunner: QueryRunner): Promise<void> {
+		await queryRunner.query(`ALTER TABLE "emojis" DROP COLUMN column_name "user_id"`);
+		await queryRunner.query(`ALTER TABLE "emojis" DROP CONSTRAINT FK_fa7ddd5f9a214e28ce596548421`);
+	}
+}