From 4efb1cfaf6ad3c4e97b835b8436be494707c8ea9 Mon Sep 17 00:00:00 2001 From: Jack Andrews Date: Fri, 1 Sep 2023 01:06:06 +0100 Subject: [PATCH] emails using database package --- apps/emails/package.json | 3 +- .../migrations/20230219190916_/migration.sql | 225 --------------- .../20230219231320_null_allow/migration.sql | 8 - .../20230220001329_email_queue/migration.sql | 29 -- .../migrations/20230220002242_/migration.sql | 11 - .../20230220005811_fromimap/migration.sql | 12 - .../20230221233223_uuid/migration.sql | 187 ------------ .../20230227225201_autoinc/migration.sql | 2 - .../prisma/migrations/migration_lock.toml | 3 - apps/emails/prisma/prisma.js | 2 - apps/emails/prisma/schema.prisma | 273 ------------------ apps/emails/server.js | 2 +- yarn.lock | 42 +-- 13 files changed, 11 insertions(+), 788 deletions(-) delete mode 100644 apps/emails/prisma/migrations/20230219190916_/migration.sql delete mode 100644 apps/emails/prisma/migrations/20230219231320_null_allow/migration.sql delete mode 100644 apps/emails/prisma/migrations/20230220001329_email_queue/migration.sql delete mode 100644 apps/emails/prisma/migrations/20230220002242_/migration.sql delete mode 100644 apps/emails/prisma/migrations/20230220005811_fromimap/migration.sql delete mode 100644 apps/emails/prisma/migrations/20230221233223_uuid/migration.sql delete mode 100644 apps/emails/prisma/migrations/20230227225201_autoinc/migration.sql delete mode 100644 apps/emails/prisma/migrations/migration_lock.toml delete mode 100644 apps/emails/prisma/prisma.js delete mode 100644 apps/emails/prisma/schema.prisma diff --git a/apps/emails/package.json b/apps/emails/package.json index 433a0ac23..4ef04a973 100644 --- a/apps/emails/package.json +++ b/apps/emails/package.json @@ -10,13 +10,12 @@ "author": "", "license": "ISC", "dependencies": { - "@prisma/client": "^4.15.0", "dotenv": "^16.0.3", "express": "^4.18.2", "imap": "^0.8.19", "mail-listener5": "^2.1.2", "mailparser": "^3.6.3", - "prisma": "^4.15.0" + "database": "*" }, "devDependencies": { "concurrently": "^7.6.0", diff --git a/apps/emails/prisma/migrations/20230219190916_/migration.sql b/apps/emails/prisma/migrations/20230219190916_/migration.sql deleted file mode 100644 index e22c54384..000000000 --- a/apps/emails/prisma/migrations/20230219190916_/migration.sql +++ /dev/null @@ -1,225 +0,0 @@ --- CreateEnum -CREATE TYPE "Hook" AS ENUM ('ticket_created', 'ticket_status_changed'); - --- CreateTable -CREATE TABLE "User" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "name" TEXT NOT NULL, - "password" TEXT NOT NULL, - "email" TEXT NOT NULL, - "isAdmin" BOOLEAN NOT NULL, - "language" TEXT DEFAULT 'en', - "notify_ticket_created" BOOLEAN NOT NULL DEFAULT true, - "notify_ticket_status_changed" BOOLEAN NOT NULL DEFAULT true, - "notify_ticket_comments" BOOLEAN NOT NULL DEFAULT true, - "notify_ticket_assigned" BOOLEAN NOT NULL DEFAULT true, - "teamId" INTEGER, - - CONSTRAINT "User_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Team" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "name" TEXT NOT NULL, - "levels" JSONB, - - CONSTRAINT "Team_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Ticket" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "name" TEXT NOT NULL, - "title" TEXT NOT NULL, - "detail" TEXT, - "email" TEXT NOT NULL, - "note" TEXT, - "isComplete" BOOLEAN NOT NULL, - "priority" TEXT NOT NULL, - "clientId" INTEGER NOT NULL, - "userId" INTEGER, - "linked" JSONB, - "teamId" INTEGER, - - CONSTRAINT "Ticket_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Client" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "name" TEXT NOT NULL, - "email" TEXT NOT NULL, - "contactName" TEXT NOT NULL, - "number" TEXT, - "notes" TEXT, - "active" BOOLEAN NOT NULL DEFAULT true, - - CONSTRAINT "Client_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "UserFile" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "filename" TEXT NOT NULL, - "path" TEXT NOT NULL, - "userId" INTEGER NOT NULL, - - CONSTRAINT "UserFile_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "TicketFile" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "filename" TEXT NOT NULL, - "path" TEXT NOT NULL, - "ticketId" INTEGER NOT NULL, - - CONSTRAINT "TicketFile_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Notes" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "title" TEXT NOT NULL, - "note" TEXT NOT NULL, - "Favourited" BOOLEAN NOT NULL DEFAULT false, - "userId" INTEGER NOT NULL, - - CONSTRAINT "Notes_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Todos" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "text" TEXT NOT NULL, - "done" BOOLEAN NOT NULL DEFAULT false, - "userId" INTEGER NOT NULL, - - CONSTRAINT "Todos_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Webhooks" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "name" TEXT NOT NULL, - "url" TEXT NOT NULL, - "type" "Hook" NOT NULL, - "active" BOOLEAN NOT NULL, - "secret" TEXT, - "createdBy" TEXT NOT NULL, - - CONSTRAINT "Webhooks_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Discord" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "name" TEXT NOT NULL, - "secret" TEXT, - "url" TEXT NOT NULL, - "active" BOOLEAN NOT NULL DEFAULT false, - - CONSTRAINT "Discord_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Slack" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "name" TEXT NOT NULL, - "secret" TEXT, - "url" TEXT NOT NULL, - "active" BOOLEAN NOT NULL DEFAULT false, - - CONSTRAINT "Slack_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Email" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "active" BOOLEAN NOT NULL DEFAULT false, - "user" TEXT NOT NULL, - "pass" TEXT NOT NULL, - "secure" BOOLEAN NOT NULL DEFAULT false, - "host" TEXT NOT NULL, - "reply" TEXT NOT NULL, - "port" TEXT NOT NULL, - - CONSTRAINT "Email_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Config" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "notifications" JSONB NOT NULL, - - CONSTRAINT "Config_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Imap_Email" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "from" TEXT NOT NULL, - "subject" TEXT NOT NULL, - "body" TEXT NOT NULL, - "text" TEXT NOT NULL, - "html" TEXT NOT NULL, - - CONSTRAINT "Imap_Email_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); - --- CreateIndex -CREATE UNIQUE INDEX "Client_email_key" ON "Client"("email"); - --- AddForeignKey -ALTER TABLE "User" ADD CONSTRAINT "User_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Ticket" ADD CONSTRAINT "Ticket_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Ticket" ADD CONSTRAINT "Ticket_clientId_fkey" FOREIGN KEY ("clientId") REFERENCES "Client"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Ticket" ADD CONSTRAINT "Ticket_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "UserFile" ADD CONSTRAINT "UserFile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TicketFile" ADD CONSTRAINT "TicketFile_ticketId_fkey" FOREIGN KEY ("ticketId") REFERENCES "Ticket"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Notes" ADD CONSTRAINT "Notes_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Todos" ADD CONSTRAINT "Todos_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/apps/emails/prisma/migrations/20230219231320_null_allow/migration.sql b/apps/emails/prisma/migrations/20230219231320_null_allow/migration.sql deleted file mode 100644 index 8abc4f24a..000000000 --- a/apps/emails/prisma/migrations/20230219231320_null_allow/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ --- DropForeignKey -ALTER TABLE "Ticket" DROP CONSTRAINT "Ticket_clientId_fkey"; - --- AlterTable -ALTER TABLE "Ticket" ALTER COLUMN "clientId" DROP NOT NULL; - --- AddForeignKey -ALTER TABLE "Ticket" ADD CONSTRAINT "Ticket_clientId_fkey" FOREIGN KEY ("clientId") REFERENCES "Client"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/apps/emails/prisma/migrations/20230220001329_email_queue/migration.sql b/apps/emails/prisma/migrations/20230220001329_email_queue/migration.sql deleted file mode 100644 index 8340c1655..000000000 --- a/apps/emails/prisma/migrations/20230220001329_email_queue/migration.sql +++ /dev/null @@ -1,29 +0,0 @@ --- AlterTable -ALTER TABLE "Imap_Email" ADD COLUMN "emailQueueId" INTEGER, -ALTER COLUMN "from" DROP NOT NULL, -ALTER COLUMN "subject" DROP NOT NULL, -ALTER COLUMN "body" DROP NOT NULL, -ALTER COLUMN "text" DROP NOT NULL, -ALTER COLUMN "html" DROP NOT NULL; - --- CreateTable -CREATE TABLE "EmailQueue" ( - "id" SERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "name" TEXT NOT NULL, - "username" TEXT NOT NULL, - "password" TEXT NOT NULL, - "hostname" TEXT NOT NULL, - "tls" BOOLEAN NOT NULL DEFAULT true, - "teams" JSONB, - "teamId" INTEGER, - - CONSTRAINT "EmailQueue_pkey" PRIMARY KEY ("id") -); - --- AddForeignKey -ALTER TABLE "Imap_Email" ADD CONSTRAINT "Imap_Email_emailQueueId_fkey" FOREIGN KEY ("emailQueueId") REFERENCES "EmailQueue"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "EmailQueue" ADD CONSTRAINT "EmailQueue_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/apps/emails/prisma/migrations/20230220002242_/migration.sql b/apps/emails/prisma/migrations/20230220002242_/migration.sql deleted file mode 100644 index aeecbf42f..000000000 --- a/apps/emails/prisma/migrations/20230220002242_/migration.sql +++ /dev/null @@ -1,11 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `teamId` on the `EmailQueue` table. All the data in the column will be lost. - -*/ --- DropForeignKey -ALTER TABLE "EmailQueue" DROP CONSTRAINT "EmailQueue_teamId_fkey"; - --- AlterTable -ALTER TABLE "EmailQueue" DROP COLUMN "teamId"; diff --git a/apps/emails/prisma/migrations/20230220005811_fromimap/migration.sql b/apps/emails/prisma/migrations/20230220005811_fromimap/migration.sql deleted file mode 100644 index bfd652896..000000000 --- a/apps/emails/prisma/migrations/20230220005811_fromimap/migration.sql +++ /dev/null @@ -1,12 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `levels` on the `Team` table. All the data in the column will be lost. - - Added the required column `fromImap` to the `Ticket` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "Team" DROP COLUMN "levels"; - --- AlterTable -ALTER TABLE "Ticket" ADD COLUMN "fromImap" BOOLEAN NOT NULL; diff --git a/apps/emails/prisma/migrations/20230221233223_uuid/migration.sql b/apps/emails/prisma/migrations/20230221233223_uuid/migration.sql deleted file mode 100644 index 743292b70..000000000 --- a/apps/emails/prisma/migrations/20230221233223_uuid/migration.sql +++ /dev/null @@ -1,187 +0,0 @@ -/* - Warnings: - - - The primary key for the `Client` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `Config` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `Discord` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `Email` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `EmailQueue` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `Imap_Email` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `Notes` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `Slack` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `Team` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `Ticket` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `TicketFile` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `Todos` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `UserFile` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `Webhooks` table will be changed. If it partially fails, the table could be left without primary key constraint. - -*/ --- DropForeignKey -ALTER TABLE "Imap_Email" DROP CONSTRAINT "Imap_Email_emailQueueId_fkey"; - --- DropForeignKey -ALTER TABLE "Notes" DROP CONSTRAINT "Notes_userId_fkey"; - --- DropForeignKey -ALTER TABLE "Ticket" DROP CONSTRAINT "Ticket_clientId_fkey"; - --- DropForeignKey -ALTER TABLE "Ticket" DROP CONSTRAINT "Ticket_teamId_fkey"; - --- DropForeignKey -ALTER TABLE "Ticket" DROP CONSTRAINT "Ticket_userId_fkey"; - --- DropForeignKey -ALTER TABLE "TicketFile" DROP CONSTRAINT "TicketFile_ticketId_fkey"; - --- DropForeignKey -ALTER TABLE "Todos" DROP CONSTRAINT "Todos_userId_fkey"; - --- DropForeignKey -ALTER TABLE "User" DROP CONSTRAINT "User_teamId_fkey"; - --- DropForeignKey -ALTER TABLE "UserFile" DROP CONSTRAINT "UserFile_userId_fkey"; - --- AlterTable -ALTER TABLE "Client" DROP CONSTRAINT "Client_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ADD CONSTRAINT "Client_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "Client_id_seq"; - --- AlterTable -ALTER TABLE "Config" DROP CONSTRAINT "Config_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ADD CONSTRAINT "Config_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "Config_id_seq"; - --- AlterTable -ALTER TABLE "Discord" DROP CONSTRAINT "Discord_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ADD CONSTRAINT "Discord_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "Discord_id_seq"; - --- AlterTable -ALTER TABLE "Email" DROP CONSTRAINT "Email_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ADD CONSTRAINT "Email_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "Email_id_seq"; - --- AlterTable -ALTER TABLE "EmailQueue" DROP CONSTRAINT "EmailQueue_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ADD CONSTRAINT "EmailQueue_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "EmailQueue_id_seq"; - --- AlterTable -ALTER TABLE "Imap_Email" DROP CONSTRAINT "Imap_Email_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ALTER COLUMN "emailQueueId" SET DATA TYPE TEXT, -ADD CONSTRAINT "Imap_Email_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "Imap_Email_id_seq"; - --- AlterTable -ALTER TABLE "Notes" DROP CONSTRAINT "Notes_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ALTER COLUMN "userId" SET DATA TYPE TEXT, -ADD CONSTRAINT "Notes_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "Notes_id_seq"; - --- AlterTable -ALTER TABLE "Slack" DROP CONSTRAINT "Slack_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ADD CONSTRAINT "Slack_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "Slack_id_seq"; - --- AlterTable -ALTER TABLE "Team" DROP CONSTRAINT "Team_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ADD CONSTRAINT "Team_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "Team_id_seq"; - --- AlterTable -ALTER TABLE "Ticket" DROP CONSTRAINT "Ticket_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ALTER COLUMN "clientId" SET DATA TYPE TEXT, -ALTER COLUMN "userId" SET DATA TYPE TEXT, -ALTER COLUMN "teamId" SET DATA TYPE TEXT, -ADD CONSTRAINT "Ticket_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "Ticket_id_seq"; - --- AlterTable -ALTER TABLE "TicketFile" DROP CONSTRAINT "TicketFile_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ALTER COLUMN "ticketId" SET DATA TYPE TEXT, -ADD CONSTRAINT "TicketFile_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "TicketFile_id_seq"; - --- AlterTable -ALTER TABLE "Todos" DROP CONSTRAINT "Todos_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ALTER COLUMN "userId" SET DATA TYPE TEXT, -ADD CONSTRAINT "Todos_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "Todos_id_seq"; - --- AlterTable -ALTER TABLE "User" DROP CONSTRAINT "User_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ALTER COLUMN "teamId" SET DATA TYPE TEXT, -ADD CONSTRAINT "User_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "User_id_seq"; - --- AlterTable -ALTER TABLE "UserFile" DROP CONSTRAINT "UserFile_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ALTER COLUMN "userId" SET DATA TYPE TEXT, -ADD CONSTRAINT "UserFile_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "UserFile_id_seq"; - --- AlterTable -ALTER TABLE "Webhooks" DROP CONSTRAINT "Webhooks_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ADD CONSTRAINT "Webhooks_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "Webhooks_id_seq"; - --- AddForeignKey -ALTER TABLE "User" ADD CONSTRAINT "User_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Ticket" ADD CONSTRAINT "Ticket_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Ticket" ADD CONSTRAINT "Ticket_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Ticket" ADD CONSTRAINT "Ticket_clientId_fkey" FOREIGN KEY ("clientId") REFERENCES "Client"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "UserFile" ADD CONSTRAINT "UserFile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TicketFile" ADD CONSTRAINT "TicketFile_ticketId_fkey" FOREIGN KEY ("ticketId") REFERENCES "Ticket"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Notes" ADD CONSTRAINT "Notes_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Todos" ADD CONSTRAINT "Todos_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Imap_Email" ADD CONSTRAINT "Imap_Email_emailQueueId_fkey" FOREIGN KEY ("emailQueueId") REFERENCES "EmailQueue"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/apps/emails/prisma/migrations/20230227225201_autoinc/migration.sql b/apps/emails/prisma/migrations/20230227225201_autoinc/migration.sql deleted file mode 100644 index 9d98c6b45..000000000 --- a/apps/emails/prisma/migrations/20230227225201_autoinc/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "Ticket" ADD COLUMN "Number" SERIAL NOT NULL; diff --git a/apps/emails/prisma/migrations/migration_lock.toml b/apps/emails/prisma/migrations/migration_lock.toml deleted file mode 100644 index fbffa92c2..000000000 --- a/apps/emails/prisma/migrations/migration_lock.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Please do not edit this file manually -# It should be added in your version-control system (i.e. Git) -provider = "postgresql" \ No newline at end of file diff --git a/apps/emails/prisma/prisma.js b/apps/emails/prisma/prisma.js deleted file mode 100644 index 755646b54..000000000 --- a/apps/emails/prisma/prisma.js +++ /dev/null @@ -1,2 +0,0 @@ -const { PrismaClient } = require("@prisma/client"); -exports.prisma = new PrismaClient(); diff --git a/apps/emails/prisma/schema.prisma b/apps/emails/prisma/schema.prisma deleted file mode 100644 index 16156d22b..000000000 --- a/apps/emails/prisma/schema.prisma +++ /dev/null @@ -1,273 +0,0 @@ -generator client { - provider = "prisma-client-js" -} - -datasource db { - provider = "postgresql" - url = env("DATABASE_URL") -} - -model Provider { - id String @id @default(uuid()) - name String - clientId String - clientSecret String - active Boolean - issuer String? - tenantId String? -} - -model Account { - id String @id @default(cuid()) - userId String - type String - provider String - providerAccountId String - refresh_token String? @db.Text - access_token String? @db.Text - expires_at Int? - token_type String? - scope String? - id_token String? @db.Text - session_state String? - refresh_token_expires_in Int? - - user User @relation(fields: [userId], references: [id], onDelete: Cascade) - - @@unique([provider, providerAccountId]) -} - -model Session { - id String @id @default(cuid()) - sessionToken String @unique - userId String - expires DateTime - user User @relation(fields: [userId], references: [id], onDelete: Cascade) -} - -model User { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - name String - password String? - email String @unique - image String? - emailVerified Boolean? - isAdmin Boolean @default(false) - language String? @default("en") - notify_ticket_created Boolean @default(true) - notify_ticket_status_changed Boolean @default(true) - notify_ticket_comments Boolean @default(true) - notify_ticket_assigned Boolean @default(true) - todos Todos[] - tickets Ticket[] - file UserFile[] - notes Notes[] - Team Team? @relation(fields: [teamId], references: [id]) - teamId String? - Comment Comment[] - Account Account[] - Session Session[] -} - -model VerificationToken { - identifier String - token String @unique - expires DateTime - - @@unique([identifier, token]) -} - -model Team { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - name String - - members User[] - Ticket Ticket[] -} - -model Ticket { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - name String - title String - detail String? - email String - note String? - isComplete Boolean - priority String - linked Json? - fromImap Boolean - Number Int @default(autoincrement()) - - TicketFile TicketFile[] - Comment Comment[] - - team Team? @relation(fields: [teamId], references: [id]) - teamId String? - assignedTo User? @relation(fields: [userId], references: [id]) - client Client? @relation(fields: [clientId], references: [id]) - clientId String? - userId String? -} - -model Comment { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - - text String - public Boolean @default(false) - - userId String - user User @relation(fields: [userId], references: [id]) - ticketId String - ticket Ticket @relation(fields: [ticketId], references: [id]) -} - -model Client { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - name String - email String @unique - contactName String - number String? - notes String? - tickets Ticket[] - active Boolean @default(true) -} - -model UserFile { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - filename String - path String - - user User @relation(fields: [userId], references: [id]) - userId String -} - -model TicketFile { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - filename String - path String - - ticketId String - ticket Ticket @relation(fields: [ticketId], references: [id]) -} - -model Notes { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - title String - note String - Favourited Boolean @default(false) - - createdBy User @relation(fields: [userId], references: [id]) - userId String -} - -model Todos { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - text String - done Boolean @default(false) - - createdBy User @relation(fields: [userId], references: [id]) - userId String -} - -model Webhooks { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - name String - url String - type Hook - active Boolean - secret String? - createdBy String -} - -model Discord { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - name String - secret String? - url String - active Boolean @default(false) -} - -model Slack { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - name String - secret String? - url String - active Boolean @default(false) -} - -model Email { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - active Boolean @default(false) - user String - pass String - secure Boolean @default(false) - host String - reply String - port String -} - -model Config { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - - notifications Json // Array of service names and an active field of TRUE OR FALSE -} - -model Imap_Email { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - - from String? - subject String? - body String? - text String? - html String? - - EmailQueue EmailQueue? @relation(fields: [emailQueueId], references: [id]) - emailQueueId String? -} - -model EmailQueue { - id String @id @default(uuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) - - name String - username String - password String - hostname String - tls Boolean @default(true) - teams Json? - - imap Imap_Email[] -} - -enum Hook { - ticket_created - ticket_status_changed -} diff --git a/apps/emails/server.js b/apps/emails/server.js index ed510c0e1..97a478f20 100644 --- a/apps/emails/server.js +++ b/apps/emails/server.js @@ -1,7 +1,7 @@ const express = require("express"); const Imap = require("imap"); const { simpleParser } = require("mailparser"); -const { PrismaClient } = require("@prisma/client"); +const { PrismaClient } = require("database"); require("dotenv").config(); diff --git a/yarn.lock b/yarn.lock index f39fffe18..c4dbcc6d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1457,13 +1457,6 @@ dependencies: "@prisma/engines-version" "4.10.1-2.aead147aa326ccb985dcfed5b065b4fdabd44b19" -"@prisma/client@^4.15.0": - version "4.16.2" - resolved "https://registry.npmjs.org/@prisma/client/-/client-4.16.2.tgz" - integrity sha512-qCoEyxv1ZrQ4bKy39GnylE8Zq31IRmm8bNhNbZx7bF2cU5aiCCnSa93J2imF88MBjn7J9eUQneNxUQVJdl/rPQ== - dependencies: - "@prisma/engines-version" "4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81" - "@prisma/client@^5.2.0": version "5.2.0" resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.2.0.tgz#cbfdd440614b38736563a7999f39922fcde0ed50" @@ -1476,30 +1469,20 @@ resolved "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.10.1-2.aead147aa326ccb985dcfed5b065b4fdabd44b19.tgz" integrity sha512-tsjTho7laDhf9EJ9EnDxAPEf7yrigSMDhniXeU4YoWc7azHAs4GPxRi2P9LTFonmHkJLMOLjR77J1oIP8Ife1w== -"@prisma/engines-version@4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81": - version "4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81" - resolved "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81.tgz" - integrity sha512-q617EUWfRIDTriWADZ4YiWRZXCa/WuhNgLTVd+HqWLffjMSPzyM5uOWoauX91wvQClSKZU4pzI4JJLQ9Kl62Qg== - "@prisma/engines-version@5.2.0-25.2804dc98259d2ea960602aca6b8e7fdc03c1758f": version "5.2.0-25.2804dc98259d2ea960602aca6b8e7fdc03c1758f" resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.2.0-25.2804dc98259d2ea960602aca6b8e7fdc03c1758f.tgz#11366e7ff031c908debf4983248d40046016de37" integrity sha512-jsnKT5JIDIE01lAeCj2ghY9IwxkedhKNvxQeoyLs6dr4ZXynetD0vTy7u6wMJt8vVPv8I5DPy/I4CFaoXAgbtg== -"@prisma/engines@4.10.1": - version "4.10.1" - resolved "https://registry.npmjs.org/@prisma/engines/-/engines-4.10.1.tgz" - integrity sha512-B3tcTxjx196nuAu1GOTKO9cGPUgTFHYRdkPkTS4m5ptb2cejyBlH9X7GOfSt3xlI7p4zAJDshJP4JJivCg9ouA== - "@prisma/engines@4.15.0": version "4.15.0" resolved "https://registry.npmjs.org/@prisma/engines/-/engines-4.15.0.tgz" integrity sha512-FTaOCGs0LL0OW68juZlGxFtYviZa4xdQj/rQEdat2txw0s3Vu/saAPKjNVXfIgUsGXmQ72HPgNr6935/P8FNAA== -"@prisma/engines@4.16.2": - version "4.16.2" - resolved "https://registry.npmjs.org/@prisma/engines/-/engines-4.16.2.tgz" - integrity sha512-vx1nxVvN4QeT/cepQce68deh/Turxy5Mr+4L4zClFuK1GlxN3+ivxfuv+ej/gvidWn1cE1uAhW7ALLNlYbRUAw== +"@prisma/engines@5.2.0": + version "5.2.0" + resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.2.0.tgz#e5dff48eb324c8137393933292d44ea5c3bc2ce7" + integrity sha512-dT7FOLUCdZmq+AunLqB1Iz+ZH/IIS1Fz2THmKZQ6aFONrQD/BQ5ecJ7g2wGS2OgyUFf4OaLam6/bxmgdOBDqig== "@prisma/nextjs-monorepo-workaround-plugin@^5.2.0": version "5.2.0" @@ -7322,13 +7305,6 @@ preview-email@^3.0.5: pug "^3.0.2" uuid "^9.0.0" -prisma@4.10.1: - version "4.10.1" - resolved "https://registry.npmjs.org/prisma/-/prisma-4.10.1.tgz" - integrity sha512-0jDxgg+DruB1kHVNlcspXQB9au62IFfVg9drkhzXudszHNUAQn0lVuu+T8np0uC2z1nKD5S3qPeCyR8u5YFLnA== - dependencies: - "@prisma/engines" "4.10.1" - prisma@4.15.0: version "4.15.0" resolved "https://registry.npmjs.org/prisma/-/prisma-4.15.0.tgz" @@ -7336,12 +7312,12 @@ prisma@4.15.0: dependencies: "@prisma/engines" "4.15.0" -prisma@^4.15.0: - version "4.16.2" - resolved "https://registry.npmjs.org/prisma/-/prisma-4.16.2.tgz" - integrity sha512-SYCsBvDf0/7XSJyf2cHTLjLeTLVXYfqp7pG5eEVafFLeT0u/hLFz/9W196nDRGUOo1JfPatAEb+uEnTQImQC1g== +prisma@5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.2.0.tgz#a302dc2635cdec1d22d552ece837fb29a03563b9" + integrity sha512-FfFlpjVCkZwrqxDnP4smlNYSH1so+CbfjgdpioFzGGqlQAEm6VHAYSzV7jJgC3ebtY9dNOhDMS2+4/1DDSM7bQ== dependencies: - "@prisma/engines" "4.16.2" + "@prisma/engines" "5.2.0" prismjs@^1.27.0: version "1.29.0"