// Use DBML to define your database structure
// Docs: https://dbml.dbdiagram.io/docs

Table meta {
  id uuid [pk, unique, not null]
  system_code varchar(50) [not null, ref: > system.code]
  tool uuid [ref: > tool.id]
  practice varchar(32) [not null]
  build varchar(250) [not null]
  enviroment varchar(250) [not null]
  library varchar(50)
  method varchar(10)
  hash varchar(500) [not null]
  created_at datetime [not null]
}

Table tool {
  id uuid [pk, unique, not null]
  tool varchar(50) [not null]
  practive varchar(20) [not null]
}

Table problem {
  id uuid [pk, unique, not null]
  executor uuid [ref: > user.id]
  is_created_manually bool
  status varchar(32) [not null]
  status_updated_at datetime [not null]
  resolution varchar(32)
  priority varchar(32) [not null]
  description varchar(500)
  remediation varchar(500)
  сategory varchar(250)
  cve varchar(50)
  cwe varchar(500)
  cvss int
  location varchar(500) [not null]
  defect_id uuid
  defect_status varchar(32)
  created_at datetime [not null]
  exception_date datetime
  category varchar(250)
  hash varchar(500) [not null]
  creator uuid [ref: > user.id]
  version int [not null]
  group_id uuid [ref: > problem_group.id ]

  meta uuid [not null, ref: > meta.id]
}

Table user {
  id uuid [pk, unique, not null]
  login varchar(100) [not null]
  is_active bool
}

Table problem_group {
  id uuid [pk, unique, not null]
  name varchar(50) [not null]
  description varchar(300)
}

Table system {
  id uuid [pk, unique, not null]
  name varchar(50) [not null]
  code varchar(50) [not null]
  buiseness_critical bool
  security_critical bool
  is_active bool

  indexes {
    id [pk]
    code
  }
}

Table user_to_system {
  system_id uuid [not null, ref: > system.id]
  user_id uuid [not null, ref: > user.id]
  indexes {
    (system_id, user_id) [pk, unique]
  }
}

Table comment {
  id uuid [pk, not null]
  problem_id uuid [not null, ref: > problem.id]
  description varchar(500) [not null]
  created_by uuid [not null, ref: > user.id]
  created_at datetime [not null]
}

Table work_history {
  id uuid [pk, not null]
  problem_id uuid [not null, ref: > problem.id]
  action varchar(100)
  old_value varchar(100)
  new_value varchar(100)
  user_id uuid [not null, ref: > user.id]
  created_at datetime [not null]
}