Church Cashbook
Schema Manual
Manual home Return to Church Cashbook

Church Cashbook Schema Manual

The notification_queue table stores outgoing email notifications, providing a queued delivery buffer with retry capability.

Purpose

Rather than sending email synchronously during a web request, the application inserts a row into notification_queue and then immediately attempts delivery. If delivery fails (SMTP unavailable, mail() returns false), the row remains in PENDING state for retry. Superadmins can view the queue and trigger retries from Admin → Notification Queue.

Table definition

CREATE TABLE notification_queue (
  id              INT UNSIGNED NOT NULL AUTO_INCREMENT,
  to_email        VARCHAR(255) NOT NULL,
  to_name         VARCHAR(255) NOT NULL DEFAULT '',
  subject         VARCHAR(255) NOT NULL,
  body_text       TEXT NOT NULL,
  status          ENUM('PENDING','SENT','FAILED') NOT NULL DEFAULT 'PENDING',
  context_type    VARCHAR(40) DEFAULT NULL,
  context_id      INT UNSIGNED DEFAULT NULL,
  attempts        TINYINT UNSIGNED NOT NULL DEFAULT 0,
  sent_at         DATETIME DEFAULT NULL,
  created_at      DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_status (status),
  KEY idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Column reference

Column Type Notes
idINT UNSIGNED PKAuto-increment primary key
to_emailVARCHAR(255)Recipient email address
to_nameVARCHAR(255)Recipient display name
subjectVARCHAR(255)Email subject line
body_textTEXTPlain text email body
statusENUMPENDING / SENT / FAILED
context_typeVARCHAR(40)Optional — what triggered the notification (e.g. ie_assigned, viewer_account_created)
context_idINT UNSIGNEDOptional — ID of the related entity (user, assignment, etc.)
attemptsTINYINT UNSIGNEDNumber of send attempts made
sent_atDATETIMETimestamp of successful delivery; NULL if not yet sent
created_atDATETIMEWhen the notification was queued

Related schema changes

The examiner_church_access table has an additional column added by migration:

ALTER TABLE examiner_church_access
  ADD COLUMN reminder_sent_at DATETIME DEFAULT NULL;

This records when the IE expiry reminder was last sent for each assignment, preventing duplicate reminders.

Migration

Applied by: public/migration_notifications_01_queue.sql