구분 차이점
한솔님과의 차이 알람/미팅 테이블, VEHICLES table type, is Admin, contractPrice 별도 존재, carCategory(vehiclesCategory) 분류
민수님과의 차이 userCount정보, imageUrl, String meeting[ ] 배열, contractPrice, contractDocuments내에서 companyId도 같이 저장
erDiagram

USERS {
  id Int PK
  name String
  email String
  employee_number String
  phone String
  password String
  company_id Int FK
  created_at DateTime
  updated_at DateTime
}

COMPANIES {
  id Int PK
  name String
  auth_code String
  created_at DateTime
  updated_at DateTime
}

VEHICLES {
  id Int PK
  company_id Int FK
  vehicle_number String
  manufacturer String
  model String
  manufacturing_year Int
  mileage Int
  price Int
  accident_count Int
  description String
  accident_detail String
  contract_status String
  created_at DateTime
  updated_at DateTime
}

CUSTOMERS {
  id Int PK
  company_id Int FK
  name String
  gender String
  phone String
  age_group String
  region String
  email String
  memo String
  created_at DateTime
  updated_at DateTime
}

CONTRACTS {
  id Int PK
  vehicle_id Int FK
  customer_id Int FK
  user_id Int FK
  meeting_schedule DateTime
  status String
  created_at DateTime
  updated_at DateTime
}

CONTRACT_DOCUMENTS {
  id Int PK
  contract_id Int FK
  file_name String
  file_url String
  file_size Int
  uploaded_by Int FK
  created_at DateTime
  updated_at DateTime
}

BULK_UPLOADS {
  id Int PK
  user_id Int FK
  type String
  file_url String
  upload_status String
  created_at DateTime
}

%% 관계 설정

COMPANIES ||--o{ USERS : has
COMPANIES ||--o{ VEHICLES : owns
COMPANIES ||--o{ CUSTOMERS : has

USERS ||--o{ CONTRACTS : creates
VEHICLES ||--o{ CONTRACTS : involved_in
CUSTOMERS ||--o{ CONTRACTS : involved_in

CONTRACTS ||--o{ CONTRACT_DOCUMENTS : contains
USERS ||--o{ CONTRACT_DOCUMENTS : uploads
USERS ||--o{ BULK_UPLOADS : performs
erDiagram

Companies {
  INT id PK "UNIQUE, NOT NULL"
  STRING companyName "UNIQUE, NOT NULL"
  STRING companyCode "UNIQUE, NOT NULL"
  DateTime createdAt "NOT NULL"
  DateTime updatedAt "NOT NULL"
}

Users {
  INT id PK "UNIQUE, NOT NULL"
  INT companyId FK "NOT NULL"
  STRING name "NOT NULL"
  STRING email "UNIQUE, NOT NULL"
  STRING password "NOT NULL"
  STRING employeeNumber "UNIQUE, NOT NULL"
  STRING phoneNumber "NOT NULL"
  STRING imageUrl "nullable"
  BOOLEAN isAdmin "NOT NULL, DEFAULT FALSE"
  DateTime createdAt "NOT NULL"
  DateTime updatedAt "NOT NULL"
}

Customers {
  INT id PK "UNIQUE, NOT NULL"
  INT companyId FK "NOT NULL"
  STRING name "NOT NULL"
  ENUM gender "NOT NULL"
  STRING phoneNumber "NOT NULL"
  ENUM ageGroup "nullable"
  ENUM region "nullable"
  STRING email "NOT NULL"
  STRING memo "nullable"
  INT contractCount "NOT NULL, DEFAULT 0"
  DateTime createdAt "NOT NULL"
  DateTime updatedAt "NOT NULL"
}

Cars {
  INT id PK "UNIQUE, NOT NULL"
  INT companyId FK "NOT NULL"
  INT manufacturerId FK "NOT NULL"
  INT modelId FK "NOT NULL"
  STRING carNumber "UNIQUE, NOT NULL"
  INT manufacturingYear "NOT NULL"
  INT mileage "NOT NULL"
  INT price "NOT NULL"
  INT accidentCount "NOT NULL"
  STRING explanation "NOT NULL"
  STRING accidentDetails "NOT NULL"
  ENUM carStatus "NOT NULL, DEFAULT possession"
  DateTime createdAt "NOT NULL"
  DateTime updatedAt "NOT NULL"
}

Manufacturers {
  INT id PK "UNIQUE, NOT NULL"
  STRING name "NOT NULL"
  DateTime createdAt "NOT NULL"
  DateTime updatedAt "NOT NULL"
}

CarModels {
  INT id PK "UNIQUE, NOT NULL"
  INT manufacturerId FK "NOT NULL"
  STRING name "NOT NULL"
  STRING type "NOT NULL"
  DateTime createdAt "NOT NULL"
  DateTime updatedAt "NOT NULL"
}

Contracts {
  INT id PK "UNIQUE, NOT NULL"
  INT userId FK "NOT NULL"
  INT carId FK "NOT NULL"
  INT customerId FK "NOT NULL"
  ENUM contractStatus "NOT NULL, DEFAULT carInspection"
  DateTime resolutionDate "nullable"
  INT contractPrice "NOT NULL"
  DateTime createdAt "NOT NULL"
  DateTime updatedAt "NOT NULL"
}

Meetings {
  INT id PK "UNIQUE, NOT NULL"
  INT contractId FK "NOT NULL"
  DateTime date "NOT NULL"
  DateTime createdAt "NOT NULL"
  DateTime updatedAt "NOT NULL"
}

Alarms {
  INT id PK "UNIQUE, NOT NULL"
  INT meetingId FK "NOT NULL"
  DateTime time "NOT NULL"
  DateTime createdAt "NOT NULL"
  DateTime updatedAt "NOT NULL"
}

ContractDocuments {
  INT id PK "UNIQUE, NOT NULL"
  INT contractId FK "nullable"
  INT companyId FK "NOT NULL"
  STRING fileName "NOT NULL"
  STRING filePath "NOT NULL"
  INT fileSize "NOT NULL"
  DateTime createdAt "NOT NULL"
  DateTime updatedAt "NOT NULL"
}

%% 관계 정의
Companies ||--o{ Users : "employs"
Companies ||--o{ Customers : "serves"
Companies ||--o{ Cars : "owns"
Companies ||--o{ ContractDocuments : "has"

Users ||--o{ Contracts : "manages"
Customers ||--o{ Contracts : "makes"
Cars ||--o{ Contracts : "relatedTo"

Contracts ||--o{ Meetings : "has"
Meetings ||--o{ Alarms : "has"
Contracts ||--o{ ContractDocuments : "includes"

Manufacturers ||--o{ CarModels : "has"
CarModels ||--o{ Cars : "models"