//// ------------------------------------------------------
//// THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
//// ------------------------------------------------------

Project "AssetFlow" {
  database_type: ''
  Note: ''
}

Table alerts {
  id Int [pk, increment]
  type alertType [not null]
  message String
  actionplan actionPlan
  actionplanId Int
  date DateTime [not null]
  state alertState [not null]
  acknowledged_by alertContacts [not null]
  acknowledged_at DateTime
}

Table alertContacts {
  id Int [pk, increment]
  name String [not null]
  phone String [unique, not null]
  comment String
  prios priorities [not null]
  alerts alerts [not null]
}

Table actionPlan {
  id Int [pk, increment]
  name String [not null]
  comment String
  alert_hook String [unique, not null]
  prio priorities [not null]
  content content [not null]
  alerts alerts [not null]
}

Table priorities {
  id Int [pk, increment]
  Contact alertContacts [not null]
  contactId Int [not null]
  priority Int [not null]
  actionplan actionPlan [not null]
  actionplanId Int [not null]

  indexes {
    (priority, actionplanId) [unique]
  }
}

Table content {
  id Int [pk, increment]
  type contentType [not null]
  name String [not null]
  filename String [not null]
  actionplan actionPlan [not null]
}

Table alertContactsToalerts {
  acknowledged_byId Int [ref: > alertContacts.id]
  alertsId Int [ref: > alerts.id]
}

Table actionPlanTocontent {
  contentId Int [ref: > content.id]
  actionplanId Int [ref: > actionPlan.id]
}

Enum contentType {
  voice_alarm
  voice_explainer
  voice_acknowledgement
  voice_ending
}

Enum alertType {
  generic
  fire
  fault
  intrusion
  clear
}

Enum alertState {
  incomming
  running
  failed
  acknowledged
}

Ref: alerts.actionplanId > actionPlan.id

Ref: priorities.contactId > alertContacts.id

Ref: priorities.actionplanId > actionPlan.id