feature(dashboard): add integrations and notifications

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-10-02 22:12:05 +02:00
parent d920f6951c
commit f65a633403
94 changed files with 3692 additions and 127 deletions

View File

@@ -0,0 +1,71 @@
-- CreateEnum
CREATE TYPE "IntegrationType" AS ENUM ('app', 'mail', 'custom');
-- CreateTable
CREATE TABLE "notification_settings" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"projectId" TEXT NOT NULL,
"settings" JSONB NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "notification_settings_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "notifications" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"projectId" TEXT NOT NULL,
"title" TEXT NOT NULL,
"message" TEXT NOT NULL,
"isReadAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"integrationId" UUID,
"integrationType" "IntegrationType" NOT NULL,
CONSTRAINT "notifications_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "integrations" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"name" TEXT NOT NULL,
"type" TEXT NOT NULL,
"config" JSONB NOT NULL,
"organizationId" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "integrations_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "_IntegrationToNotificationControl" (
"A" UUID NOT NULL,
"B" UUID NOT NULL
);
-- CreateIndex
CREATE UNIQUE INDEX "_IntegrationToNotificationControl_AB_unique" ON "_IntegrationToNotificationControl"("A", "B");
-- CreateIndex
CREATE INDEX "_IntegrationToNotificationControl_B_index" ON "_IntegrationToNotificationControl"("B");
-- AddForeignKey
ALTER TABLE "notification_settings" ADD CONSTRAINT "notification_settings_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "projects"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "projects"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_integrationId_fkey" FOREIGN KEY ("integrationId") REFERENCES "integrations"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "integrations" ADD CONSTRAINT "integrations_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "organizations"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_IntegrationToNotificationControl" ADD CONSTRAINT "_IntegrationToNotificationControl_A_fkey" FOREIGN KEY ("A") REFERENCES "integrations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_IntegrationToNotificationControl" ADD CONSTRAINT "_IntegrationToNotificationControl_B_fkey" FOREIGN KEY ("B") REFERENCES "notification_settings"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,14 @@
/*
Warnings:
- You are about to drop the column `integrationType` on the `notifications` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "notification_settings" ADD COLUMN "sendToApp" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "sendToEmail" BOOLEAN NOT NULL DEFAULT false;
-- AlterTable
ALTER TABLE "notifications" DROP COLUMN "integrationType",
ADD COLUMN "sendToApp" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "sendToEmail" BOOLEAN NOT NULL DEFAULT false;

View File

@@ -0,0 +1,14 @@
/*
Warnings:
- You are about to drop the column `type` on the `integrations` table. All the data in the column will be lost.
- You are about to drop the column `settings` on the `notification_settings` table. All the data in the column will be lost.
- Added the required column `config` to the `notification_settings` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "integrations" DROP COLUMN "type";
-- AlterTable
ALTER TABLE "notification_settings" DROP COLUMN "settings",
ADD COLUMN "config" JSONB NOT NULL;

View File

@@ -0,0 +1,55 @@
/*
Warnings:
- You are about to drop the `_IntegrationToNotificationControl` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `notification_settings` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "_IntegrationToNotificationControl" DROP CONSTRAINT "_IntegrationToNotificationControl_A_fkey";
-- DropForeignKey
ALTER TABLE "_IntegrationToNotificationControl" DROP CONSTRAINT "_IntegrationToNotificationControl_B_fkey";
-- DropForeignKey
ALTER TABLE "notification_settings" DROP CONSTRAINT "notification_settings_projectId_fkey";
-- DropTable
DROP TABLE "_IntegrationToNotificationControl";
-- DropTable
DROP TABLE "notification_settings";
-- CreateTable
CREATE TABLE "notification_rules" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"projectId" TEXT NOT NULL,
"sendToApp" BOOLEAN NOT NULL DEFAULT false,
"sendToEmail" BOOLEAN NOT NULL DEFAULT false,
"config" JSONB NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "notification_rules_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "_IntegrationToNotificationRule" (
"A" UUID NOT NULL,
"B" UUID NOT NULL
);
-- CreateIndex
CREATE UNIQUE INDEX "_IntegrationToNotificationRule_AB_unique" ON "_IntegrationToNotificationRule"("A", "B");
-- CreateIndex
CREATE INDEX "_IntegrationToNotificationRule_B_index" ON "_IntegrationToNotificationRule"("B");
-- AddForeignKey
ALTER TABLE "notification_rules" ADD CONSTRAINT "notification_rules_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "projects"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_IntegrationToNotificationRule" ADD CONSTRAINT "_IntegrationToNotificationRule_A_fkey" FOREIGN KEY ("A") REFERENCES "integrations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_IntegrationToNotificationRule" ADD CONSTRAINT "_IntegrationToNotificationRule_B_fkey" FOREIGN KEY ("B") REFERENCES "notification_rules"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `name` to the `notification_rules` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "notification_rules" ADD COLUMN "name" TEXT NOT NULL;

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "notifications" ADD COLUMN "payload" JSONB;

View File

@@ -5,6 +5,10 @@ generator client {
provider = "prisma-client-js"
}
generator json {
provider = "prisma-json-types-generator"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
@@ -30,6 +34,7 @@ model Organization {
Client Client[]
Dashboard Dashboard[]
ShareOverview ShareOverview[]
integrations Integration[]
@@map("organizations")
}
@@ -87,6 +92,9 @@ model Project {
references Reference[]
access ProjectAccess[]
notificationRules NotificationRule[]
notifications Notification[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@ -299,3 +307,59 @@ model Reference {
@@map("references")
}
enum IntegrationType {
app
mail
custom
}
model NotificationRule {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String
projectId String
project Project @relation(fields: [projectId], references: [id])
integrations Integration[]
sendToApp Boolean @default(false)
sendToEmail Boolean @default(false)
/// [IPrismaNotificationRuleConfig]
config Json
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@map("notification_rules")
}
model Notification {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
projectId String
project Project @relation(fields: [projectId], references: [id])
title String
message String
isReadAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
sendToApp Boolean @default(false)
sendToEmail Boolean @default(false)
integration Integration? @relation(fields: [integrationId], references: [id])
integrationId String? @db.Uuid
/// [IPrismaNotificationPayload]
payload Json?
@@map("notifications")
}
model Integration {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String
/// [IPrismaIntegrationConfig]
config Json
organization Organization @relation(fields: [organizationId], references: [id])
organizationId String
notificationRules NotificationRule[]
notifications Notification[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@map("integrations")
}