diff --git a/concord-server/migrations/20250927230554_timestampify/migration.sql b/concord-server/migrations/20250927230554_timestampify/migration.sql new file mode 100644 index 0000000..7285123 --- /dev/null +++ b/concord-server/migrations/20250927230554_timestampify/migration.sql @@ -0,0 +1,71 @@ +/* + Warnings: + + - Added the required column `updatedAt` to the `Category` table without a default value. This is not possible if the table is not empty. + - Added the required column `pinnedId` to the `Channel` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `Channel` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `Instance` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `Message` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `Reply` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `Role` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `User` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `UserAuth` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "public"."Category" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "public"."Channel" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "pinnedId" TEXT, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "public"."Instance" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "public"."Message" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "public"."MessagePing" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "public"."Reply" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "public"."Role" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "public"."User" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "public"."UserAuth" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- CreateTable +CREATE TABLE "public"."ChannelPin" ( + "messageId" TEXT NOT NULL, + "channelId" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- CreateIndex +CREATE UNIQUE INDEX "ChannelPin_messageId_key" ON "public"."ChannelPin"("messageId"); + +-- CreateIndex +CREATE UNIQUE INDEX "ChannelPin_channelId_key" ON "public"."ChannelPin"("channelId"); + +-- CreateIndex +CREATE UNIQUE INDEX "ChannelPin_messageId_channelId_key" ON "public"."ChannelPin"("messageId", "channelId"); + +-- AddForeignKey +ALTER TABLE "public"."ChannelPin" ADD CONSTRAINT "ChannelPin_messageId_fkey" FOREIGN KEY ("messageId") REFERENCES "public"."Message"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "public"."ChannelPin" ADD CONSTRAINT "ChannelPin_channelId_fkey" FOREIGN KEY ("channelId") REFERENCES "public"."Channel"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/concord-server/migrations/20250927231139_pinnedidnullable/migration.sql b/concord-server/migrations/20250927231139_pinnedidnullable/migration.sql new file mode 100644 index 0000000..4614fa0 --- /dev/null +++ b/concord-server/migrations/20250927231139_pinnedidnullable/migration.sql @@ -0,0 +1,26 @@ +-- AlterTable +ALTER TABLE "public"."Category" ALTER COLUMN "updatedAt" DROP DEFAULT; + +-- AlterTable +ALTER TABLE "public"."Channel" ALTER COLUMN "updatedAt" DROP DEFAULT; + +-- AlterTable +ALTER TABLE "public"."Channel" ALTER COLUMN "pinnedId" DROP NOT NULL; + +-- AlterTable +ALTER TABLE "public"."Instance" ALTER COLUMN "updatedAt" DROP DEFAULT; + +-- AlterTable +ALTER TABLE "public"."Message" ALTER COLUMN "updatedAt" DROP DEFAULT; + +-- AlterTable +ALTER TABLE "public"."Reply" ALTER COLUMN "updatedAt" DROP DEFAULT; + +-- AlterTable +ALTER TABLE "public"."Role" ALTER COLUMN "updatedAt" DROP DEFAULT; + +-- AlterTable +ALTER TABLE "public"."User" ALTER COLUMN "updatedAt" DROP DEFAULT; + +-- AlterTable +ALTER TABLE "public"."UserAuth" ALTER COLUMN "updatedAt" DROP DEFAULT; diff --git a/concord-server/schema.prisma b/concord-server/schema.prisma index ab40935..a4fbfa8 100644 --- a/concord-server/schema.prisma +++ b/concord-server/schema.prisma @@ -12,11 +12,13 @@ datasource db { } model Instance { - id String @id @default(uuid(7)) - name String - icon String? - Role Role[] - Category Category[] + id String @id @default(uuid(7)) + name String + icon String? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + Role Role[] + Category Category[] } model User { @@ -28,6 +30,8 @@ model User { banner String? admin Boolean status String // online/offline/dnd/idle/invis + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt Role Role[] UserAuth UserAuth? Message Message[] @@ -35,20 +39,24 @@ model User { } model Role { - User User @relation(fields: [userId], references: [id]) - userId String - Instance Instance @relation(fields: [instanceId], references: [id]) - instanceId String - type String + User User @relation(fields: [userId], references: [id]) + userId String + Instance Instance @relation(fields: [instanceId], references: [id]) + instanceId String + type String + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @@unique([userId, instanceId]) } model UserAuth { - User User @relation(fields: [userId], references: [id]) - userId String - password String // HASHED PASSWORD AS STRING USING SHA-256 - token String? // current user token + User User @relation(fields: [userId], references: [id]) + userId String + password String // HASHED PASSWORD AS STRING USING SHA-256 + token String? // current user token + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @@unique([userId]) } @@ -59,17 +67,34 @@ model Category { instanceId String? name String position Int + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt Channel Channel[] } model Channel { - id String @id @default(uuid(7)) + id String @id @default(uuid(7)) type String - Category Category? @relation(fields: [categoryId], references: [id]) + Category Category? @relation(fields: [categoryId], references: [id]) categoryId String? name String description String + pinnedId String? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt Message Message[] + ChannelPin ChannelPin? +} + +model ChannelPin { + messageId String @unique + channelId String @unique + + Message Message @relation(fields: [messageId], references: [id]) + Channel Channel @relation(fields: [channelId], references: [id]) + createdAt DateTime @default(now()) + + @@unique([messageId, channelId]) } model Message { @@ -80,25 +105,31 @@ model Message { userId String deleted Boolean text String + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt replies Reply? @relation("MessageToReply") repliedTo Reply? @relation("ReplyToMessage") MessagePing MessagePing[] + ChannelPin ChannelPin? } model Reply { - message Message @relation("MessageToReply", fields: [messageId], references: [id]) //message text - messageId String @unique //message id of the reply - repliesTo Message @relation("ReplyToMessage", fields: [repliesToId], references: [id]) //message id that this message replies to - repliesToId String @unique //replies to this message id + message Message @relation("MessageToReply", fields: [messageId], references: [id]) //message text + messageId String @unique //message id of the reply + repliesTo Message @relation("ReplyToMessage", fields: [repliesToId], references: [id]) //message id that this message replies to + repliesToId String @unique //replies to this message id + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @@unique([messageId, repliesToId]) } model MessagePing { - Message Message @relation(fields: [messageId], references: [id]) + Message Message @relation(fields: [messageId], references: [id]) messageId String - PingsUser User @relation(fields: [pingsUserId], references: [id]) + PingsUser User @relation(fields: [pingsUserId], references: [id]) pingsUserId String + createdAt DateTime @default(now()) @@unique([messageId, pingsUserId]) }