From 77b87dcc3165a74c5952ff86a474409440d9fda7 Mon Sep 17 00:00:00 2001 From: Eric Cabrel TIOGO Date: Sun, 23 Jun 2024 00:54:37 +0200 Subject: [PATCH] chore(database): remove isfavorite column (#71) * chore(database): remove isfavorite column * fix: tests in the ci --- .../features/folders/graphql/folder.resolvers.ts | 5 +++++ .../migration.sql | 14 ++++++++++++++ packages/domain/prisma/schema.prisma | 3 +-- .../src/services/folders/folder.service.test.ts | 3 +-- .../folders/inputs/create-folder-input.test.ts | 1 - .../services/folders/inputs/create-folder-input.ts | 1 - .../inputs/create-user-root-folder-input.test.ts | 1 - .../inputs/create-user-root-folder-input.ts | 1 - .../folders/inputs/update-folder-input.test.ts | 1 - 9 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 packages/domain/prisma/migrations/20240622222249_remove_is_favorite_in_folders_table/migration.sql diff --git a/apps/backend/src/features/folders/graphql/folder.resolvers.ts b/apps/backend/src/features/folders/graphql/folder.resolvers.ts index 08c93a4f..7a37fa24 100644 --- a/apps/backend/src/features/folders/graphql/folder.resolvers.ts +++ b/apps/backend/src/features/folders/graphql/folder.resolvers.ts @@ -118,4 +118,9 @@ export class FolderResolvers { return folders.length + snippets.length; } + + @ResolveField() + async isFavorite(@Parent() _folder: Folder): Promise { + return false; + } } diff --git a/packages/domain/prisma/migrations/20240622222249_remove_is_favorite_in_folders_table/migration.sql b/packages/domain/prisma/migrations/20240622222249_remove_is_favorite_in_folders_table/migration.sql new file mode 100644 index 00000000..24b48a05 --- /dev/null +++ b/packages/domain/prisma/migrations/20240622222249_remove_is_favorite_in_folders_table/migration.sql @@ -0,0 +1,14 @@ +/* + Warnings: + + - You are about to drop the column `is_favorite` on the `folders` table. All the data in the column will be lost. + +*/ +-- DropIndex +DROP INDEX `folders_is_favorite_idx` ON `folders`; + +-- AlterTable +ALTER TABLE `folders` DROP COLUMN `is_favorite`; + +-- CreateIndex +CREATE INDEX `folders_category_idx` ON `folders`(`category`); diff --git a/packages/domain/prisma/schema.prisma b/packages/domain/prisma/schema.prisma index d0ea4772..14c4490a 100644 --- a/packages/domain/prisma/schema.prisma +++ b/packages/domain/prisma/schema.prisma @@ -76,7 +76,6 @@ model Folder { parentId String? @map("parent_id") name String @db.VarChar(255) path String? @db.Text - isFavorite Boolean @default(false) @map("is_favorite") category FolderCategory @default(visible) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") @@ -87,7 +86,7 @@ model Folder { @@unique([userId, parentId, name], name: "folder_name_unique_constraint") @@index([name]) - @@index([isFavorite]) + @@index([category]) @@index([userId]) @@index([parentId]) @@map("folders") diff --git a/packages/domain/src/services/folders/folder.service.test.ts b/packages/domain/src/services/folders/folder.service.test.ts index 6c5fd34a..f65cf7e9 100644 --- a/packages/domain/src/services/folders/folder.service.test.ts +++ b/packages/domain/src/services/folders/folder.service.test.ts @@ -60,8 +60,8 @@ describe('Test Folder service', () => { const expectedFolder = await folderService.create(createFolderInput); expect(expectedFolder).toMatchObject({ + category: 'visible', id: createFolderInput.toFolder().id, - isFavorite: false, name: createFolderInput.name, parentId: rootFolder.id, userId: user.id, @@ -354,7 +354,6 @@ describe('Test Folder service', () => { category: 'visible', createdAt: expect.any(Date), id: folder.id, - isFavorite: false, name: folderToUpdate.name, parentId: rootFolder.id, path: folder.path, diff --git a/packages/domain/src/services/folders/inputs/create-folder-input.test.ts b/packages/domain/src/services/folders/inputs/create-folder-input.test.ts index c8a9c253..182616eb 100644 --- a/packages/domain/src/services/folders/inputs/create-folder-input.test.ts +++ b/packages/domain/src/services/folders/inputs/create-folder-input.test.ts @@ -15,7 +15,6 @@ describe('Test Create Folder Input', () => { category: 'visible', createdAt: expect.any(Date), id: expect.any(String), - isFavorite: false, name: 'blogs', parentId: 'cl23rzwe5000002czaedc8sll', path: null, diff --git a/packages/domain/src/services/folders/inputs/create-folder-input.ts b/packages/domain/src/services/folders/inputs/create-folder-input.ts index 2cec1224..d163a2d1 100644 --- a/packages/domain/src/services/folders/inputs/create-folder-input.ts +++ b/packages/domain/src/services/folders/inputs/create-folder-input.ts @@ -31,7 +31,6 @@ export class CreateFolderInput { category: 'visible', createdAt: new Date(), id: this.folderId, - isFavorite: false, name: this._input.name, parentId: this._input.parentId, path: null, diff --git a/packages/domain/src/services/folders/inputs/create-user-root-folder-input.test.ts b/packages/domain/src/services/folders/inputs/create-user-root-folder-input.test.ts index d01d93f5..9c10a2da 100644 --- a/packages/domain/src/services/folders/inputs/create-user-root-folder-input.test.ts +++ b/packages/domain/src/services/folders/inputs/create-user-root-folder-input.test.ts @@ -11,7 +11,6 @@ describe('Test Create User Root Folder Input', () => { category: 'visible', createdAt: expect.any(Date), id: expect.any(String), - isFavorite: false, name: '__dm34saxf6111113dabfed9tmm__', parentId: null, path: null, diff --git a/packages/domain/src/services/folders/inputs/create-user-root-folder-input.ts b/packages/domain/src/services/folders/inputs/create-user-root-folder-input.ts index 0c23f307..9bf3a391 100644 --- a/packages/domain/src/services/folders/inputs/create-user-root-folder-input.ts +++ b/packages/domain/src/services/folders/inputs/create-user-root-folder-input.ts @@ -13,7 +13,6 @@ export class CreateUserRootFolderInput { category: 'visible', createdAt: new Date(), id: this.folderId, - isFavorite: false, name: `__${this._userId}__`, parentId: null, path: null, diff --git a/packages/domain/src/services/folders/inputs/update-folder-input.test.ts b/packages/domain/src/services/folders/inputs/update-folder-input.test.ts index 787d1e7b..b751415c 100644 --- a/packages/domain/src/services/folders/inputs/update-folder-input.test.ts +++ b/packages/domain/src/services/folders/inputs/update-folder-input.test.ts @@ -21,7 +21,6 @@ describe('Test Update Folder Input', () => { category: 'visible', createdAt: currentFolder.createdAt, id: currentFolder.id, - isFavorite: currentFolder.isFavorite, name: 'folder updated', parentId: currentFolder.parentId, path: currentFolder.path,