le super migration timestamp style on it

This commit is contained in:
Kevin Puig
2025-09-27 19:13:22 -04:00
parent 0ee3984262
commit 74d0c502f3
3 changed files with 150 additions and 22 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -15,6 +15,8 @@ model Instance {
id String @id @default(uuid(7))
name String
icon String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Role Role[]
Category Category[]
}
@@ -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[]
@@ -40,6 +44,8 @@ model Role {
Instance Instance @relation(fields: [instanceId], references: [id])
instanceId String
type String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([userId, instanceId])
}
@@ -49,6 +55,8 @@ model UserAuth {
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,6 +67,8 @@ model Category {
instanceId String?
name String
position Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Channel Channel[]
}
@@ -69,7 +79,22 @@ model Channel {
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,9 +105,12 @@ 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 {
@@ -90,6 +118,8 @@ model Reply {
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])
}
@@ -99,6 +129,7 @@ model MessagePing {
messageId String
PingsUser User @relation(fields: [pingsUserId], references: [id])
pingsUserId String
createdAt DateTime @default(now())
@@unique([messageId, pingsUserId])
}