SQL

CREATE TABLE registration  (
  id                   INTEGER PRIMARY KEY AUTOINCREMENT,
  event_id             INTEGER NOT NULL,
  first_name           TEXT    NOT NULL,
  last_name            TEXT    NOT NULL,
  -- COLLATE NOCASE makes the database compare emails case-insensitively,
  -- so the unique index below also blocks duplicates that differ only in
    -- case (A@example.com vs a@example.com).
    email                TEXT    NOT NULL COLLATE NOCASE,
  phone                TEXT,
  -- optional contact number
    organisation         TEXT,
  -- optional company/college
    attendee_type        TEXT    NOT NULL DEFAULT 'Professional'
                         CHECK (attendee_type IN ('Professional', 'Student', 'Other')),
  dietary_requirements TEXT,
  -- optional,
  for catering
    -- Cancelling sets status to 'cancelled' instead of deleting the row,
  so
    -- the organisers keep a record and the place is freed automatically.
    status               TEXT    NOT NULL DEFAULT 'confirmed'
                         CHECK (status IN ('confirmed', 'cancelled')),
  created_at           TEXT    NOT NULL DEFAULT (datetime('now')),
  updated_at           TEXT    NOT NULL DEFAULT (datetime('now')),
  FOREIGN KEY (event_id) REFERENCES event (id)
)

Columns

Column Data type Allow null Primary key Actions
id INTEGER read-only
event_id INTEGER read-only
first_name TEXT read-only
last_name TEXT read-only
email TEXT read-only
phone TEXT read-only
organisation TEXT read-only
attendee_type TEXT read-only
dietary_requirements TEXT read-only
status TEXT read-only
created_at TEXT read-only
updated_at TEXT read-only

Foreign Keys

Column Destination
event_id event.id

Indexes

Name Columns Unique SQL Drop?
one_active_registration_per_event
  • event_id
  • email
SQL
CREATE UNIQUE INDEX one_active_registration_per_event
ON registration (event_id, email)
    WHERE status = 'confirmed'
read-only