Skip to main content

Enums and notes

Enums (public and schema-qualified, aliased, quoted values, value notes) and every place a note can go: project, table (both syntaxes), column, index, enum value. Multi-line notes use ''' strings and may contain Markdown.

Covers: Enums (public, schema-qualified, aliased with as, quoted values with spaces and emoji, value notes); notes on project, table (Note: and Note { }), column, index; multi-line ''' notes with Markdown (headings, lists, links, tables)

03-enums-and-notes.dbml
03-enums-and-notes.dbmlpublic.customers.id < public.tickets.customer_idpublic.agents.id < public.tickets.assignee_idpublic.tickets.id < public.ticket_comments.ticket_idpublic.agents.id < public.ticket_comments.author_agent_idcustomers People who open ticketscustomershas noteid integer · primary key · incrementidintegername varchar(200) · not nullnameNNvarchar(200)email varchar(255) · unique · not null Lower-cased before insertemailUNNvarchar(255)agents Support staff. One row per human; bots live in `automations`.agentshas noteid integer · primary key · incrementidintegername varchar(200) · not nullnameNNvarchar(200)team varchar(50)teamvarchar(50)tickets A **ticket** is one support conversation. | status | meaning | |---------|----------------------| | new | untriaged | | pending | waiting on customer | ticketshas noteid integer · primary key · incrementidintegercustomer_id integer · foreign key · not nullcustomer_idNNintegerassignee_id integer · foreign keyassignee_idintegerstatus ticket_status · not null · default: newstatusNNticket_statuspriority ticket_priority · not null · default: normalpriorityNNticket_prioritychannel support.channel · not null Enum referenced through its aliaschannelNNsupport.channelrating satisfactionratingsatisfactionsubject varchar(300) · not nullsubjectNNvarchar(300)status_code smallint Legacy numeric status kept for the old reporting job: 💸 1 = processing, ✔️ 2 = shipped, ❌ 3 = cancelled, 😔 4 = refunded status_codesmallintcreated_at timestamp · not null · default: now()created_atNNtimestampsupport.channel_settingssupport.channel_settingschannel support.channel · primary key Enum referenced by its qualified namechannelsupport.channelenabled boolean · not null · default: trueenabledNNbooleanfirst_response_minutes integerfirst_response_minutesintegerticket_commentsticket_commentsid integer · primary key · incrementidintegerticket_id integer · foreign key · not nullticket_idNNintegerauthor_agent_id integer · foreign keyauthor_agent_idintegerbody text · not null Markdown, rendered in the agent UIbodyNNtextis_internal boolean · not null · default: falseis_internalNNbooleancreated_at timestamp · not null · default: now()created_atNNtimestamp

Source​

examples/03-enums-and-notes.dbml
examples/03-enums-and-notes.dbml
// Enums (public and schema-qualified, aliased, quoted values, value notes) and every
// place a note can go: project, table (both syntaxes), column, index, enum value.
// Multi-line notes use ''' strings and may contain Markdown.

Project helpdesk {
database_type: 'PostgreSQL'
Note: '''
# Helpdesk

Support ticketing schema.

## Conventions
* all timestamps are UTC
* soft deletes are **not** used; closed tickets stay forever
* see [the runbook](https://example.com/runbook) for escalation rules
'''
}

enum ticket_status {
new [note: 'Created, nobody looked at it yet']
open
pending [note: 'Waiting on the customer']
solved
closed
}

enum ticket_priority {
low
normal
high
urgent [note: 'Pages the on-call agent']
}

enum support.channel as Channel {
email
chat
phone
"web form"
}

enum satisfaction {
"😀 good"
"😐 okay"
"🙁 bad"
"Not Yet Rated"
}

Table customers {
id integer [pk, increment]
name varchar(200) [not null]
email varchar(255) [not null, unique, note: 'Lower-cased before insert']
Note: 'People who open tickets'
}

Table agents {
id integer [pk, increment]
name varchar(200) [not null]
team varchar(50)

Note {
'Support staff. One row per human; bots live in `automations`.'
}
}

Table tickets {
id integer [pk, increment]
customer_id integer [not null, ref: > customers.id]
assignee_id integer [ref: > agents.id]
status ticket_status [not null, default: 'new']
priority ticket_priority [not null, default: 'normal']
channel Channel [not null, note: 'Enum referenced through its alias']
rating satisfaction
subject varchar(300) [not null]
status_code smallint [
note: '''
Legacy numeric status kept for the old reporting job:
💸 1 = processing,
✔️ 2 = shipped,
❌ 3 = cancelled,
😔 4 = refunded
'''
]
created_at timestamp [not null, default: `now()`]

indexes {
(status, priority) [name: 'tickets_queue_idx', note: 'Drives the agent queue view']
created_at [note: 'Range scans for SLA reports']
}

Note: '''
A **ticket** is one support conversation.

| status | meaning |
|---------|----------------------|
| new | untriaged |
| pending | waiting on customer |
'''
}

Table support.channel_settings {
channel support.channel [pk, note: 'Enum referenced by its qualified name']
enabled boolean [not null, default: true]
first_response_minutes integer
}

Table ticket_comments {
id integer [pk, increment]
ticket_id integer [not null, ref: > tickets.id]
author_agent_id integer [ref: > agents.id]
body text [not null, note: 'Markdown, rendered in the agent UI']
is_internal boolean [not null, default: false]
created_at timestamp [not null, default: `now()`]
}