From f4114a48962a6395d49345e70f86ba84cc7d944d Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Mon, 1 Dec 2025 11:28:26 -0600 Subject: [PATCH] sechema changes+migrations --- assets/openapi.json | Bin 891224 -> 892878 bytes assets/schemas.json | Bin 383174 -> 384531 bytes src/schemas/api/channels/Channel.ts | 8 ++++++ src/util/entities/Channel.ts | 14 +++++++++- src/util/entities/Message.ts | 10 +++++++ .../postgres/1764609924756-threads.ts | 25 ++++++++++++++++++ .../postgres/1764610059742-threadtypo.ts | 25 ++++++++++++++++++ 7 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/util/migrations/postgres/1764609924756-threads.ts create mode 100644 src/util/migrations/postgres/1764610059742-threadtypo.ts diff --git a/assets/openapi.json b/assets/openapi.json index d641fe628f65d6bb08f00ec88f1c785fff7af45a..230af20d7613cb196e39bc11b47621e28f33784a 100644 GIT binary patch delta 489 zcmYL^KS&!<9LIU@-g}qCSaTpq{Rb|kg_0qd=%6)=G$I6xg_aIpuI6Z@(X+|vq*Sb! zRSfmJDVd}dYOumBrCvLin&M)uNF213BF!L<;!`6XKJews_xFL{?ndPMR%B+Ayt5Gf z$JM+)k-$P9*+<||$W-t5!d+%RvA)LYu=bwKL$_%+qPyfNdiF>Nu2%_SV239$Ga|mB z7~Gd-nz9TavdV;V^m zR@e}`jQFxayHN7+Fv^@fN98x^Mc|AD5#13CuV;mDT7M{q?VjsPeH3FSycvnlzB~M? z!lxtN@&7OPk$f>^a(eGkr_^nOybpFHiTObsij^Q=2AcJSSpbqv0(I)Hk1eH15`dTo-bH2j32X> z%LT?G^e)^Iji^^1Q%Ct!X}hs%2dq&uCTvTuTJ_{a#(=h{G~vS$6STT#X>0f;v<4E& Y#p7HeB&x(C@k)G>8j0VD$7_B47fpS-C;$Ke delta 124 zcmX@N-|WUFvxY5hWSwN^bg#u zSEmPDVrHBEwv{b*JCN03GQGf;Np<=HYfgdo^BgSO&vUR!d9)u1VFh9~AZ7<*4j|?P RVlE)&24bG=M?!eHya8NaF=_w+ diff --git a/assets/schemas.json b/assets/schemas.json index 46a36939bb19c24f6c05ed2d85a36daf53d6595b..d1017ec4ad559ed9d555a39dd1f9f55f066030fd 100644 GIT binary patch delta 429 zcmX@MQGD_q@rEso+UC<6o-zARpTNx&Jn*Rwnl8&KFr-KrFWDN+OIp(-(*V#rPap~e;&g*lX0_?IuNY;gJDg delta 121 zcmV-<0EYjQycfo?7l5<@D>s*r3j$k~H3JuyZTq&3D4Fn#S b5Mu=ohudxgx7%(6EeeNNd<3^xd { type: ChannelType.DM | ChannelType.GROUP_DM; diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts index a250758fa..1d52fa016 100644 --- a/src/util/entities/Channel.ts +++ b/src/util/entities/Channel.ts @@ -31,7 +31,7 @@ import { User } from "./User"; import { VoiceState } from "./VoiceState"; import { Webhook } from "./Webhook"; import { Member } from "./Member"; -import { ChannelPermissionOverwrite, ChannelPermissionOverwriteType, ChannelType, PublicUserProjection } from "@spacebar/schemas"; +import { ChannelPermissionOverwrite, ChannelPermissionOverwriteType, ChannelType, PublicUserProjection, threadMetadata } from "@spacebar/schemas"; @Entity({ name: "channels", @@ -152,6 +152,18 @@ export class Channel extends BaseClass { @Column({ nullable: true }) default_thread_rate_limit_per_user?: number = 0; + @Column({ type: "simple-json", nullable: true }) + thread_metadata?: threadMetadata; + + @Column({ nullable: true }) + member_count?: number; + + @Column({ nullable: true }) + message_count?: number; + + @Column({ nullable: true }) + total_message_sent?: number; + /** Must be calculated Channel.calculatePosition */ position: number; diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts index 508ffd8ca..c38f60abd 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts @@ -48,6 +48,16 @@ export class Message extends BaseClass { }) channel: Channel; + @Column({ nullable: true }) + @RelationId((message: Message) => message.thread) + thread_id?: string; + + @JoinColumn({ name: "channel_id" }) + @ManyToOne(() => Channel, { + onDelete: "CASCADE", + }) + thread?: Channel; + @Column({ nullable: true }) @RelationId((message: Message) => message.guild) guild_id?: string; diff --git a/src/util/migrations/postgres/1764609924756-threads.ts b/src/util/migrations/postgres/1764609924756-threads.ts new file mode 100644 index 000000000..efa2ce7f4 --- /dev/null +++ b/src/util/migrations/postgres/1764609924756-threads.ts @@ -0,0 +1,25 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Threads1764609924756 implements MigrationInterface { + name = "Threads1764609924756"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "messages" DROP CONSTRAINT "FK_bb3af7f695d50083e6523290d41"`); + await queryRunner.query(`ALTER TABLE "channels" DROP COLUMN "total_message_sent"`); + await queryRunner.query(`ALTER TABLE "channels" ADD "total_messsage_sent" integer`); + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "thread_metadata" DROP NOT NULL`); + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "member_count" DROP NOT NULL`); + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "message_count" DROP NOT NULL`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "message_count" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "member_count" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "thread_metadata" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "channels" DROP COLUMN "total_messsage_sent"`); + await queryRunner.query(`ALTER TABLE "channels" ADD "total_message_sent" integer NOT NULL`); + await queryRunner.query( + `ALTER TABLE "messages" ADD CONSTRAINT "FK_bb3af7f695d50083e6523290d41" FOREIGN KEY ("thread_id") REFERENCES "channels"("id") ON DELETE CASCADE ON UPDATE NO ACTION`, + ); + } +} diff --git a/src/util/migrations/postgres/1764610059742-threadtypo.ts b/src/util/migrations/postgres/1764610059742-threadtypo.ts new file mode 100644 index 000000000..2fe2a985a --- /dev/null +++ b/src/util/migrations/postgres/1764610059742-threadtypo.ts @@ -0,0 +1,25 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Threadtypo1764610059742 implements MigrationInterface { + name = "Threadtypo1764610059742"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "messages" DROP CONSTRAINT "FK_bb3af7f695d50083e6523290d41"`); + await queryRunner.query(`ALTER TABLE "channels" DROP COLUMN "total_message_sent"`); + await queryRunner.query(`ALTER TABLE "channels" ADD "total_messsage_sent" integer`); + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "thread_metadata" DROP NOT NULL`); + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "member_count" DROP NOT NULL`); + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "message_count" DROP NOT NULL`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "message_count" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "member_count" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "channels" ALTER COLUMN "thread_metadata" SET NOT NULL`); + await queryRunner.query(`ALTER TABLE "channels" DROP COLUMN "total_messsage_sent"`); + await queryRunner.query(`ALTER TABLE "channels" ADD "total_message_sent" integer NOT NULL`); + await queryRunner.query( + `ALTER TABLE "messages" ADD CONSTRAINT "FK_bb3af7f695d50083e6523290d41" FOREIGN KEY ("thread_id") REFERENCES "channels"("id") ON DELETE CASCADE ON UPDATE NO ACTION`, + ); + } +}