Files
Backend-Iasis/prisma/schema.prisma

562 lines
18 KiB
Plaintext

generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-3.0.x"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum Role {
ADMIN
OPERATOR
CLIENT
GESTOR_PROJETOS
PO
FISCAL_CONTRATO
GESTOR_CONTRATO
}
enum DeliverableStatus {
RASCUNHO
EMITIDA
EM_EXECUCAO
AGUARDANDO_VALIDACAO
EM_REVISAO
APROVADA
GLOSADA
ENCERRADA
CANCELADA
AGUARDANDO_PAGAMENTO
PAGA
}
enum TimelineEventType {
CRIACAO
EDICAO
STATUS_CHANGE
ASSIGNMENT
BACKLOG
ANOTACAO
ALOCACAO
VALOR_RECALCULADO
}
enum BacklogItemStatus {
PENDENTE
ACEITO
REJEITADO
}
enum NoteType {
OBSERVACAO
RISCO
IMPEDIMENTO
DECISAO
}
enum SprintType {
DESCOBERTA
DESIGN
ARQUITETURA
CONSTRUCAO
}
enum WorkOrderStatus {
RASCUNHO
EMITIDA
EM_EXECUCAO
TOTALMENTE_PAGA
CANCELADA
}
enum DeliverableType {
DESCOBERTA
DESIGN
ARQUITETURA
CONSTRUCAO
MANUTENCAO
LICENCA
}
enum ContractItemType {
UST
SAAS_LICENSE
}
enum SprintStatus {
RASCUNHO
EM_EXECUCAO
FINALIZADA
CANCELADA
}
enum SprintHistoryEventType {
ENTREGAVEL_ADICIONADO
ENTREGAVEL_REMOVIDO
STATUS_CHANGE
ENTREGAVEL_MOVIDO
}
enum IntegrationScope {
DELIVERABLES_READ
CLIENTS_READ
}
model User {
id String @id @default(uuid())
name String
email String @unique
password String
role Role @default(GESTOR_PROJETOS)
clientSubRole String? @map("client_sub_role")
isActive Boolean @default(true)
mustChangePassword Boolean @default(false)
clientId String? @map("client_id")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
client Client? @relation(fields: [clientId], references: [id])
passwordResetTokens PasswordResetToken[]
@@map("users")
}
model PasswordResetToken {
id String @id @default(uuid())
userId String @map("user_id")
tokenHash String @unique @map("token_hash")
expiresAt DateTime @map("expires_at")
usedAt DateTime? @map("used_at")
createdAt DateTime @default(now()) @map("created_at")
user User @relation(fields: [userId], references: [id])
@@index([userId])
@@map("password_reset_tokens")
}
model Client {
id String @id @default(uuid())
name String
document String?
email String?
phone String?
contactName String? @map("contact_name")
description String?
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
contracts Contract[]
contractItems ContractItem[]
deliverables Deliverable[]
users User[]
profiles ClientProfile[]
allocationTemplates AllocationTemplate[]
@@map("clients")
}
model ContractItem {
id String @id @default(uuid())
code String
name String
description String?
totalUst Decimal @map("total_ust")
ustValue Decimal? @map("ust_value")
itemType ContractItemType @default(UST) @map("item_type")
timeboxDescoberta Decimal? @map("timebox_descoberta")
timeboxDesign Decimal? @map("timebox_design")
timeboxArquitetura Decimal? @map("timebox_arquitetura")
timeboxConstrucao Decimal? @map("timebox_construcao")
isActive Boolean @default(true) @map("is_active")
clientId String @map("client_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
client Client @relation(fields: [clientId], references: [id])
deliverables Deliverable[]
allocationTemplates AllocationTemplate[]
workOrders WorkOrder[]
@@unique([code, clientId])
@@map("contract_items")
}
model Professional {
id String @id @default(uuid())
name String
document String?
email String?
phone String?
role String?
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deliverableAssignments DeliverableAssignment[]
@@map("professionals")
}
model Contract {
id String @id @default(uuid())
clientId String @map("client_id")
name String
code String?
description String?
startDate DateTime? @map("start_date")
endDate DateTime? @map("end_date")
ustValue Decimal? @map("ust_value")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
client Client @relation(fields: [clientId], references: [id])
projects Project[]
deliverables Deliverable[]
workOrders WorkOrder[]
@@map("contracts")
}
model Project {
id String @id @default(uuid())
contractId String @map("contract_id")
name String
code String?
description String?
startDate DateTime? @map("start_date")
endDate DateTime? @map("end_date")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
contract Contract @relation(fields: [contractId], references: [id])
deliverables Deliverable[]
workOrders WorkOrderProject[]
@@map("projects")
}
model Sprint {
id String @id @default(uuid())
name String
code String?
status SprintStatus @default(RASCUNHO)
startDate DateTime @map("start_date")
endDate DateTime @map("end_date")
goal String?
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deliverables Deliverable[]
history SprintHistory[] @relation("SprintHistory")
targetHistory SprintHistory[] @relation("SprintHistoryTarget")
@@map("sprints")
}
model Deliverable {
id String @id @default(uuid())
code String @unique
title String
description String?
status DeliverableStatus @default(RASCUNHO)
type DeliverableType
clientId String @map("client_id")
contractId String @map("contract_id")
projectId String @map("project_id")
contractItemId String @map("contract_item_id")
workOrderId String @map("work_order_id")
sprintId String @map("sprint_id")
startDate DateTime @map("start_date")
expectedEndDate DateTime @map("expected_end_date")
numWeeks Int @map("num_weeks")
timeboxManutencao Decimal? @map("timebox_manutencao")
ustValue Decimal? @map("ust_value")
ustQuantity Decimal? @map("ust_quantity")
totalValue Decimal? @map("total_value")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
createdBy String? @map("created_by")
updatedBy String? @map("updated_by")
client Client @relation(fields: [clientId], references: [id])
contract Contract @relation(fields: [contractId], references: [id])
project Project @relation(fields: [projectId], references: [id])
contractItem ContractItem @relation(fields: [contractItemId], references: [id])
workOrder WorkOrder @relation(fields: [workOrderId], references: [id])
sprint Sprint @relation(fields: [sprintId], references: [id])
statusHistory DeliverableStatusHistory[]
assignments DeliverableAssignment[]
backlogItems DeliverableBacklogItem[]
timelineEvents TimelineEvent[]
notes Note[]
sprintHistory SprintHistory[]
allocations DeliverableAllocation[]
@@map("deliverables")
}
model DeliverableStatusHistory {
id String @id @default(uuid())
deliverableId String @map("deliverable_id")
previousStatus DeliverableStatus? @map("previous_status")
newStatus DeliverableStatus @map("new_status")
observation String?
createdAt DateTime @default(now()) @map("created_at")
createdBy String? @map("created_by")
deliverable Deliverable @relation(fields: [deliverableId], references: [id])
@@map("deliverable_status_history")
}
model DeliverableAssignment {
id String @id @default(uuid())
deliverableId String @map("deliverable_id")
professionalId String @map("professional_id")
role String?
startDate DateTime? @map("start_date")
endDate DateTime? @map("end_date")
observation String?
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
createdBy String? @map("created_by")
deliverable Deliverable @relation(fields: [deliverableId], references: [id])
professional Professional @relation(fields: [professionalId], references: [id])
@@map("deliverable_assignments")
}
model DeliverableBacklogItem {
id String @id @default(uuid())
deliverableId String @map("deliverable_id")
title String
description String?
acceptanceCriteria String? @map("acceptance_criteria")
status BacklogItemStatus @default(PENDENTE)
rejectionReason String? @map("rejection_reason")
sortOrder Int @default(0) @map("sort_order")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
createdBy String? @map("created_by")
updatedBy String? @map("updated_by")
deliverable Deliverable @relation(fields: [deliverableId], references: [id])
@@map("deliverable_backlog_items")
}
model TimelineEvent {
id String @id @default(uuid())
deliverableId String @map("deliverable_id")
type TimelineEventType
title String
description String?
metadata Json?
createdAt DateTime @default(now()) @map("created_at")
createdBy String? @map("created_by")
deliverable Deliverable @relation(fields: [deliverableId], references: [id])
@@map("timeline_events")
}
model Note {
id String @id @default(uuid())
deliverableId String @map("deliverable_id")
type NoteType
title String
description String?
isRelevant Boolean @default(false) @map("is_relevant")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
createdBy String? @map("created_by")
updatedBy String? @map("updated_by")
deliverable Deliverable @relation(fields: [deliverableId], references: [id])
@@map("notes")
}
model SprintHistory {
id String @id @default(uuid())
sprintId String @map("sprint_id")
eventType SprintHistoryEventType @map("event_type")
description String
deliverableId String? @map("deliverable_id")
targetSprintId String? @map("target_sprint_id")
previousStatus SprintStatus? @map("previous_status")
newStatus SprintStatus? @map("new_status")
createdAt DateTime @default(now()) @map("created_at")
createdBy String? @map("created_by")
sprint Sprint @relation("SprintHistory", fields: [sprintId], references: [id])
targetSprint Sprint? @relation("SprintHistoryTarget", fields: [targetSprintId], references: [id])
deliverable Deliverable? @relation(fields: [deliverableId], references: [id])
@@map("sprint_history")
}
model ClientProfile {
id String @id @default(uuid())
name String
isActive Boolean @default(true) @map("is_active")
clientId String @map("client_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
client Client @relation(fields: [clientId], references: [id])
allocationTemplateItems AllocationTemplateItem[]
deliverableAllocations DeliverableAllocation[]
@@map("client_profiles")
}
model AllocationTemplate {
id String @id @default(uuid())
clientId String @map("client_id")
sprintType SprintType @map("sprint_type")
contractItemId String @map("contract_item_id")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
client Client @relation(fields: [clientId], references: [id])
contractItem ContractItem @relation(fields: [contractItemId], references: [id])
items AllocationTemplateItem[]
@@unique([clientId, sprintType, contractItemId])
@@map("allocation_templates")
}
model AllocationTemplateItem {
id String @id @default(uuid())
templateId String @map("template_id")
profileId String @map("profile_id")
quantity Int
allocationPercentage Decimal @map("allocation_percentage")
template AllocationTemplate @relation(fields: [templateId], references: [id], onDelete: Cascade)
profile ClientProfile @relation(fields: [profileId], references: [id])
@@map("allocation_template_items")
}
model DeliverableAllocation {
id String @id @default(uuid())
deliverableId String @map("deliverable_id")
profileId String @map("profile_id")
quantity Int
allocationPercentage Decimal @map("allocation_percentage")
calculatedValue Decimal? @map("calculated_value")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
createdBy String? @map("created_by")
deliverable Deliverable @relation(fields: [deliverableId], references: [id])
profile ClientProfile @relation(fields: [profileId], references: [id])
@@map("deliverable_allocations")
}
model WorkOrder {
id String @id @default(uuid())
code String
name String
description String?
contractId String @map("contract_id")
contractItemId String @map("contract_item_id")
reservedUst Decimal @map("reserved_ust")
totalValue Decimal? @map("total_value")
status WorkOrderStatus @default(RASCUNHO)
startDate DateTime @map("start_date")
endDate DateTime? @map("end_date")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
createdBy String? @map("created_by")
updatedBy String? @map("updated_by")
contract Contract @relation(fields: [contractId], references: [id])
contractItem ContractItem @relation(fields: [contractItemId], references: [id])
projects WorkOrderProject[]
deliverables Deliverable[]
statusHistory WorkOrderStatusHistory[]
@@unique([code, contractId])
@@map("work_orders")
}
model WorkOrderProject {
workOrderId String @map("work_order_id")
projectId String @map("project_id")
createdAt DateTime @default(now()) @map("created_at")
workOrder WorkOrder @relation(fields: [workOrderId], references: [id], onDelete: Cascade)
project Project @relation(fields: [projectId], references: [id])
@@id([workOrderId, projectId])
@@map("work_order_projects")
}
model WorkOrderStatusHistory {
id String @id @default(uuid())
workOrderId String @map("work_order_id")
previousStatus WorkOrderStatus? @map("previous_status")
newStatus WorkOrderStatus @map("new_status")
observation String?
createdAt DateTime @default(now()) @map("created_at")
createdBy String? @map("created_by")
workOrder WorkOrder @relation(fields: [workOrderId], references: [id])
@@map("work_order_status_history")
}
model IntegrationApiKey {
id String @id @default(uuid())
name String
hashedKey String @unique @map("hashed_key")
lastFourChars String @map("last_four_chars")
scopes IntegrationScope[]
isActive Boolean @default(true) @map("is_active")
expiresAt DateTime? @map("expires_at")
lastUsedAt DateTime? @map("last_used_at")
rateLimitPerMinute Int @default(60) @map("rate_limit_per_minute")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
createdBy String? @map("created_by")
updatedBy String? @map("updated_by")
usages IntegrationApiKeyUsage[]
@@map("integration_api_keys")
}
model IntegrationApiKeyUsage {
id String @id @default(uuid())
apiKeyId String @map("api_key_id")
endpoint String
statusCode Int @map("status_code")
ipAddress String? @map("ip_address")
userAgent String? @map("user_agent")
createdAt DateTime @default(now()) @map("created_at")
apiKey IntegrationApiKey @relation(fields: [apiKeyId], references: [id])
@@index([apiKeyId])
@@map("integration_api_key_usage")
}