feat: add notification system database models
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "NotificationPreference" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"userId" TEXT NOT NULL,
|
||||
"globalEnabled" BOOLEAN NOT NULL DEFAULT true,
|
||||
"orderCreated" BOOLEAN NOT NULL DEFAULT true,
|
||||
"orderStatusChanged" BOOLEAN NOT NULL DEFAULT true,
|
||||
"orderMessageReceived" BOOLEAN NOT NULL DEFAULT true,
|
||||
"paymentStatusChanged" BOOLEAN NOT NULL DEFAULT true,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "NotificationPreference_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "AdminNotificationSettings" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"emailEnabled" BOOLEAN NOT NULL DEFAULT true,
|
||||
"telegramEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
"telegramChatId" TEXT,
|
||||
"newOrder" BOOLEAN NOT NULL DEFAULT true,
|
||||
"newOrderMessage" BOOLEAN NOT NULL DEFAULT true,
|
||||
"newReview" BOOLEAN NOT NULL DEFAULT true,
|
||||
"authCodeDuplicate" BOOLEAN NOT NULL DEFAULT false,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "NotificationLog" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"userId" TEXT,
|
||||
"eventType" TEXT NOT NULL,
|
||||
"channel" TEXT NOT NULL,
|
||||
"status" TEXT NOT NULL,
|
||||
"error" TEXT,
|
||||
"payload" TEXT NOT NULL,
|
||||
"attempts" INTEGER NOT NULL DEFAULT 0,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "NotificationLog_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "NotificationPreference_userId_key" ON "NotificationPreference"("userId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "NotificationPreference_userId_idx" ON "NotificationPreference"("userId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "NotificationLog_status_createdAt_idx" ON "NotificationLog"("status", "createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "NotificationLog_userId_createdAt_idx" ON "NotificationLog"("userId", "createdAt");
|
||||
@@ -0,0 +1,2 @@
|
||||
-- DropIndex
|
||||
DROP INDEX "NotificationPreference_userId_idx";
|
||||
@@ -90,6 +90,8 @@ model User {
|
||||
reviews Review[]
|
||||
orderMessageReadStates UserOrderMessageReadState[]
|
||||
oauthAccounts OAuthAccount[]
|
||||
notificationPreference NotificationPreference?
|
||||
notificationLogs NotificationLog[]
|
||||
}
|
||||
|
||||
/// Прочитанность чата по заказу (для сообщений от админа после lastReadAt)
|
||||
@@ -269,3 +271,51 @@ model InfoPageBlock {
|
||||
|
||||
@@index([published, sort])
|
||||
}
|
||||
|
||||
/// Настройки оповещений пользователя
|
||||
model NotificationPreference {
|
||||
id String @id @default(cuid())
|
||||
userId String @unique
|
||||
globalEnabled Boolean @default(true)
|
||||
orderCreated Boolean @default(true)
|
||||
orderStatusChanged Boolean @default(true)
|
||||
orderMessageReceived Boolean @default(true)
|
||||
paymentStatusChanged Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
/// Настройки оповещений админа
|
||||
model AdminNotificationSettings {
|
||||
id String @id @default(cuid())
|
||||
emailEnabled Boolean @default(true)
|
||||
telegramEnabled Boolean @default(false)
|
||||
telegramChatId String?
|
||||
newOrder Boolean @default(true)
|
||||
newOrderMessage Boolean @default(true)
|
||||
newReview Boolean @default(true)
|
||||
authCodeDuplicate Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
/// Лог отправки оповещений
|
||||
model NotificationLog {
|
||||
id String @id @default(cuid())
|
||||
userId String?
|
||||
eventType String
|
||||
channel String
|
||||
status String
|
||||
error String?
|
||||
payload String
|
||||
attempts Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([status, createdAt])
|
||||
@@index([userId, createdAt])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user