Перейти к содержимому

Simplify Project Schema — Implementation Plan

For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

Goal: Remove budget/deadline fields from the Project model and simplify project creation to title + description + optional category.

Architecture: Prisma schema change → DTO update → service update → migration. No controller changes needed — endpoints stay the same, just with fewer fields.

Tech Stack: Prisma, NestJS, class-validator, class-transformer


Files:

  • Modify: apps/core-api/prisma/schema.prisma:550-553 (remove ProjectBudgetType enum)
  • Modify: apps/core-api/prisma/schema.prisma:608-631 (simplify Project model)

Step 1: Remove ProjectBudgetType enum

Delete these lines (550-553):

enum ProjectBudgetType {
FIXED
HOURLY
}

Step 2: Simplify Project model

Replace the current Project model (lines 608-631) with:

model Project {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
title String
description String
category ProjectCategoryType?
status ProjectStatus @default(DRAFT)
customerId String @map("customer_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
walriderThread WalriderThread?
@@index([customerId])
@@index([status])
@@index([category])
@@map("projects")
}

Changes from original:

  • Removed: budgetType, budgetMin, budgetMax, currency, deadline
  • Changed: category from ProjectCategoryType to ProjectCategoryType? (nullable)

Step 3: Commit

Окно терминала
git add apps/core-api/prisma/schema.prisma
git commit -m "refactor(schema): remove budget/deadline fields from Project, make category optional"

Files:

  • Modify: libs/apis/providers/project-api/data-access/src/lib/dtos/project.dto.ts

Step 1: Rewrite project.dto.ts

Replace the entire file content with:

import { ApiProperty, OmitType, PartialType } from '@nestjs/swagger';
import { Expose, Type } from 'class-transformer';
import {
IsDate,
IsEnum,
IsInt,
IsOptional,
IsString,
IsUUID,
MaxLength,
Min,
MinLength,
} from 'class-validator';
import { Trim } from '@crewsforge-back/apis/shared';
import { ProjectCategoryType, ProjectStatus } from '@prisma/client';
// --- Base ---
export class ProjectDto {
@ApiProperty()
@Expose()
@IsUUID()
id!: string;
@ApiProperty()
@Expose()
@IsString()
@MinLength(3)
@MaxLength(255)
@Trim()
title!: string;
@ApiProperty()
@Expose()
@IsString()
@MinLength(3)
@Trim()
description!: string;
@ApiProperty({ enum: ProjectCategoryType, required: false })
@Expose()
@IsOptional()
@IsEnum(ProjectCategoryType)
category?: ProjectCategoryType | null;
@ApiProperty({ enum: ProjectStatus })
@Expose()
@IsEnum(ProjectStatus)
status!: ProjectStatus;
@ApiProperty()
@Expose()
@IsUUID()
customerId!: string;
@ApiProperty()
@Expose()
@IsDate()
createdAt!: Date;
@ApiProperty()
@Expose()
@IsDate()
updatedAt!: Date;
}
const excludeBaseField = ['id', 'createdAt', 'updatedAt'] as const;
// --- Response ---
export class ProjectResponseDto extends ProjectDto {}
// --- Create ---
export class ProjectCreateDto extends OmitType(ProjectDto, [
...excludeBaseField,
'status',
'customerId',
]) {}
// --- Update (only DRAFT) ---
export class ProjectUpdateDto extends PartialType(
OmitType(ProjectDto, [...excludeBaseField, 'status', 'customerId'])
) {}
// --- Update Status ---
export class ProjectUpdateStatusDto {
@ApiProperty({ enum: ProjectStatus })
@Expose()
@IsEnum(ProjectStatus)
status!: ProjectStatus;
}
// --- List Query ---
export class ProjectListQueryDto {
@ApiProperty({ enum: ProjectStatus, required: false })
@Expose()
@IsOptional()
@IsEnum(ProjectStatus)
status?: ProjectStatus;
@ApiProperty({ default: 1, required: false })
@Expose()
@IsOptional()
@IsInt()
@Min(1)
@Type(() => Number)
page?: number;
@ApiProperty({ default: 10, required: false })
@Expose()
@IsOptional()
@IsInt()
@Min(1)
@Type(() => Number)
perPage?: number;
}

Key changes:

  • Removed imports: IsDecimal, ProjectBudgetType
  • Removed fields: budgetType, budgetMin, budgetMax, currency, deadline
  • Changed description min length from 10 to 3
  • Changed category to optional with ? and | null

Step 2: Commit

Окно терминала
git add libs/apis/providers/project-api/data-access/src/lib/dtos/project.dto.ts
git commit -m "refactor(dto): simplify ProjectDto - remove budget/deadline fields, make category optional"

Files:

  • Modify: libs/apis/providers/project-api/features/project/src/lib/project.service.ts

Step 1: Simplify create method

Replace the create method’s data construction (lines 24-34) with:

const data: Prisma.ProjectCreateInput = {
title: dto.title,
description: dto.description,
category: dto.category ?? undefined,
customer: { connect: { id: customerId } },
};

Step 2: Simplify updateOneById method

Replace the data spread in updateOneById (lines 89-98) with:

data: {
...(dto.title !== undefined && { title: dto.title }),
...(dto.description !== undefined && { description: dto.description }),
...(dto.category !== undefined && { category: dto.category }),
},

Step 3: Commit

Окно терминала
git add libs/apis/providers/project-api/features/project/src/lib/project.service.ts
git commit -m "refactor(service): remove budget/deadline handling from ProjectService"

Step 1: Generate migration

Окно терминала
cd apps/core-api
npx prisma migrate dev --name remove_budget_deadline_from_project

This will generate a migration that:

  • Drops columns: budget_type, budget_min, budget_max, currency, deadline
  • Alters category to be nullable
  • Drops the ProjectBudgetType enum type

Step 2: Verify migration SQL

Check the generated migration file to confirm it contains the expected ALTER TABLE statements.

Step 3: Generate Prisma client

Окно терминала
npx prisma generate

Step 4: Commit

Окно терминала
git add apps/core-api/prisma/migrations/
git commit -m "migration: remove budget/deadline columns from projects table"

Step 1: Build the project

Окно терминала
npx nx build core-api

Expected: Clean build, no TypeScript errors.

Step 2: If build fails

Check for any remaining references to removed fields (budgetType, budgetMin, budgetMax, currency, deadline, ProjectBudgetType) and fix them.

Step 3: Commit any fixes

Окно терминала
git add -A
git commit -m "fix: resolve build errors from schema simplification"