feat: add folder management to document structure

- Introduced a new "Folder" table to manage document organization.
- Added foreign key relationships between "Document" and "Folder".
- Updated the TRPC router to include folder-related endpoints.
This commit is contained in:
Catalin Pit
2025-03-18 17:51:38 +02:00
parent 4156f2afce
commit 3fbf6c5842
2 changed files with 41 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
-- AlterTable
ALTER TABLE "Document" ADD COLUMN "folderId" INTEGER;
-- CreateTable
CREATE TABLE "Folder" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"userId" INTEGER NOT NULL,
"teamId" INTEGER,
"parentId" INTEGER,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Folder_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "Folder_userId_idx" ON "Folder"("userId");
-- CreateIndex
CREATE INDEX "Folder_teamId_idx" ON "Folder"("teamId");
-- CreateIndex
CREATE INDEX "Folder_parentId_idx" ON "Folder"("parentId");
-- CreateIndex
CREATE INDEX "Document_folderId_idx" ON "Document"("folderId");
-- AddForeignKey
ALTER TABLE "Folder" ADD CONSTRAINT "Folder_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Folder" ADD CONSTRAINT "Folder_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Folder" ADD CONSTRAINT "Folder_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Folder"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Document" ADD CONSTRAINT "Document_folderId_fkey" FOREIGN KEY ("folderId") REFERENCES "Folder"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@@ -3,6 +3,7 @@ import { apiTokenRouter } from './api-token-router/router';
import { authRouter } from './auth-router/router';
import { documentRouter } from './document-router/router';
import { fieldRouter } from './field-router/router';
import { folderRouter } from './folder-router/router';
import { profileRouter } from './profile-router/router';
import { recipientRouter } from './recipient-router/router';
import { shareLinkRouter } from './share-link-router/router';
@@ -16,6 +17,7 @@ export const appRouter = router({
profile: profileRouter,
document: documentRouter,
field: fieldRouter,
folder: folderRouter,
recipient: recipientRouter,
admin: adminRouter,
shareLink: shareLinkRouter,