push to maple-street

This commit is contained in:
Tiel Coder
2026-11-20 04:07:02 +00:00
parent 2cec220a24
commit 5adf1cef1f
345 changed files with 86105 additions and 1079 deletions
+697 -3
View File
@@ -18,7 +18,7 @@
*/
import { relations, sql } from "drizzle-orm";
import { pgTable, text, integer, boolean, timestamp, date, numeric, index, uniqueIndex, check, primaryKey } from "drizzle-orm/pg-core";
import { pgTable, text, integer, bigint, boolean, timestamp, date, numeric, index, uniqueIndex, check, primaryKey } from "drizzle-orm/pg-core";
/* ------------------------------------------------------------------ enums */
@@ -50,6 +50,31 @@ export type UnavailabilityStatus = (typeof UNAVAILABILITY_STATUSES)[number];
export const CONFIRMED_VIAS = ["app", "email_link", "sms_reply", "admin"] as const;
export type ConfirmedVia = (typeof CONFIRMED_VIAS)[number];
// Added in E1 (outbox). ARCHITECTURE §6.1 / §4 outbox table.
export const NOTIFICATION_CHANNELS = ["email", "sms"] as const;
export type NotificationChannel = (typeof NOTIFICATION_CHANNELS)[number];
// Added in E7 (reminder rules). ARCHITECTURE §6.2.
export const NOTIFICATION_RULE_EVENTS = [
"assignment.created",
"assignment.unconfirmed",
"slot.unfilled",
/** One-off coverage events (photo shoots: the lead time before `startsAt`). */
"event.reminder",
] as const;
export type NotificationRuleEvent = (typeof NOTIFICATION_RULE_EVENTS)[number];
/** Outbox status ladder; the domain ladder is drift-guarded against this. */
export const NOTIFICATION_STATUSES = [
"queued",
"sending",
"sent",
"failed",
"suppressed",
"cancelled",
] as const;
export type NotificationStatus = (typeof NOTIFICATION_STATUSES)[number];
/** TCPA consent source recorded on SMS opt-in (ARCHITECTURE §4.76). */
export const SMS_CONSENT_SOURCES = ["web_signup", "paper_form", "admin_import"] as const;
export type SmsConsentSource = (typeof SMS_CONSENT_SOURCES)[number];
@@ -86,6 +111,10 @@ export const users = pgTable(
{
id: text("id").primaryKey(),
email: text("email").unique().notNull(),
/** Login handle. Existing accounts backfill to their email address. */
username: text("username").notNull(),
/** Null until the person sets a password after their first magic link. */
passwordHash: text("password_hash"),
phoneE164: text("phone_e164"),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
@@ -94,6 +123,8 @@ export const users = pgTable(
status: text("status", { enum: USER_STATUSES }).notNull().default("pending_approval"),
avatarUrl: text("avatar_url"),
timezone: text("timezone").notNull().default(DEFAULT_TIMEZONE),
/** Secret token for the personal read-only ICS calendar feed. */
calendarFeedToken: text("calendar_feed_token"),
emergencyContact: text("emergency_contact"),
approvedBy: text("approved_by"),
approvedAt: timestamp("approved_at", { mode: "date", withTimezone: true }),
@@ -107,8 +138,11 @@ export const users = pgTable(
deactivatedAt: timestamp("deactivated_at", { mode: "date", withTimezone: true }),
},
(table) => [
// Case-insensitive unique login key.
index("users_email_lower_idx").on(sql`lower(${table.email})`),
// Case-insensitive unique login key. Enforced in the database as well as
// the app so a second insertion path cannot create a case-variant duplicate.
uniqueIndex("users_email_lower_key").on(sql`lower(${table.email})`),
uniqueIndex("users_username_lower_key").on(sql`lower(${table.username})`),
uniqueIndex("users_calendar_feed_token_key").on(table.calendarFeedToken),
index("users_status_idx").on(table.status),
index("users_system_role_idx").on(table.systemRole),
],
@@ -596,6 +630,16 @@ export const userSkills = pgTable(
verifiedAt: timestamp("verified_at", { mode: "date", withTimezone: true }),
/** Volunteer agrees to teach this skill (C5 mentor designation). */
mentorOptIn: boolean("mentor_opt_in").notNull().default(false),
/**
* Admin sign-off on the mentor designation (C5). `isMentorReady` requires
* it alongside the verified level and the volunteer's opt-in; the column
* exists so the flag is persisted rather than inferred from the level.
*/
mentorApprovedAt: timestamp("mentor_approved_at", {
mode: "date",
withTimezone: true,
}),
mentorApprovedBy: text("mentor_approved_by"),
/** Maintained by the system on assignment completion — never entered by hand. */
lastServedOn: date("last_served_on"),
notes: text("notes"),
@@ -680,6 +724,638 @@ export const growthGoals = pgTable(
],
);
/* ------------------------------------------- notifications outbox (E1) */
/**
* The notification outbox — the queue is a table (ARCHITECTURE §4 / §6.1).
*
* Enqueue is idempotent on `dedupe_key` (`template:ref:channel`), so publishing
* twice or re-running a rule cannot double-send. `payload_json` is fully merged
* at enqueue time (subject/html/text/links), making every row auditable and
* replayable. The dispatcher (E2) drains it; the admin log reads from it.
*/
export const notifications = pgTable(
"notifications",
{
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
channel: text("channel", { enum: NOTIFICATION_CHANNELS })
.notNull()
.default("email"),
templateKey: text("template_key").notNull(),
ruleKey: text("rule_key"),
assignmentId: text("assignment_id").references(() => assignments.id, {
onDelete: "set null",
}),
slotId: text("slot_id").references(() => slots.id, { onDelete: "set null" }),
/** Resolved destination at enqueue time (email address; E5 adds phone). */
toAddress: text("to_address").notNull(),
/** Fully merged message payload — exactly what will be sent. */
payloadJson: text("payload_json").notNull().default(""),
/** Unique per (template, reference, channel): the dedupe guarantee. */
dedupeKey: text("dedupe_key").unique().notNull(),
scheduledFor: timestamp("scheduled_for", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
status: text("status", { enum: NOTIFICATION_STATUSES })
.notNull()
.default("queued"),
attempts: integer("attempts").notNull().default(0),
providerId: text("provider_id"),
providerStatus: text("provider_status"),
error: text("error"),
sentAt: timestamp("sent_at", { mode: "date", withTimezone: true }),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true }),
},
(table) => [
// The dispatcher's only hot query: due rows in status order.
index("notifications_status_scheduled_idx").on(table.status, table.scheduledFor),
index("notifications_user_idx").on(table.userId),
index("notifications_assignment_idx").on(table.assignmentId),
],
);
/**
* Single-use record for magic-link sign-in tokens. The signed token carries a
* `jti`; `/api/dev/complete` inserts it here before establishing a session, so
* a replayed link is rejected. Rows are independent of assignments and are
* safe to prune after the token expiry window (10 minutes).
*/
export const usedMagicTokens = pgTable("used_magic_tokens", {
jti: text("jti").primaryKey(),
email: text("email").notNull(),
usedAt: timestamp("used_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
});
/**
* Single-use record for respond links (ARCHITECTURE §5.6). The signed token
* carries a `jti`; the first POST consumes it here, and a second POST with the
* same token is rejected. Rows cascade with their assignment (history cleanup).
*/
export const usedTokens = pgTable("used_tokens", {
jti: text("jti").primaryKey(),
assignmentId: text("assignment_id")
.notNull()
.references(() => assignments.id, { onDelete: "cascade" }),
action: text("action").notNull(),
usedAt: timestamp("used_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
});
/* ------------------------------------------- notification rules (E7) */
/**
* Offset-based reminder rules (ARCHITECTURE §6.2). "Friday before" is
* `offset_days = -2` at 18:00 local — a row, not code, so the church can move
* it to Thursday 20:00 without a deploy. `channel_set` is `email`, `sms` or
* `email+sms`; SMS rows are suppressed until E5.
*/
export const notificationRules = pgTable(
"notification_rules",
{
id: text("id").primaryKey(),
key: text("key").unique().notNull(),
event: text("event", { enum: NOTIFICATION_RULE_EVENTS })
.notNull()
.default("assignment.created"),
/** Days from the instance start; -2 is the Friday-before-Sunday reminder. */
offsetDays: integer("offset_days").notNull(),
sendAtLocalTime: text("send_at_local_time").notNull().default("09:00"),
channelSet: text("channel_set").notNull().default("email"),
/** null = every service. */
appliesToServiceId: text("applies_to_service_id").references(
() => services.id,
{ onDelete: "set null" },
),
active: boolean("active").notNull().default(true),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true }),
},
(table) => [
index("notification_rules_active_idx").on(table.active),
check(
"chk_notification_rules_channel",
sql`${table.channelSet} IN ('email','sms','email+sms')`,
),
],
);
/* ------------------------------------------- app settings (runtime admin) */
/**
* Small key/value store for settings an admin edits at runtime — currently the
* email sender identity and where admin test/failure mail goes. Kept out of
* the seed reset: these are deployment choices, not demo data.
*/
export const appSettings = pgTable("app_settings", {
key: text("key").primaryKey(),
value: text("value").notNull(),
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
});
/* --------------------------------------------------- training (lessons) */
/**
* Training content authored in the app (F2). Lessons are ordered, can be
* published/unpublished, and carry plain-text/Markdown-ish bodies. Attachments
* live in `training_resources` (bytes on disk, metadata here).
*/
export const trainingLessons = pgTable(
"training_lessons",
{
id: text("id").primaryKey(),
title: text("title").notNull(),
summary: text("summary"),
body: text("body").notNull().default(""),
published: boolean("published").notNull().default(false),
sortOrder: integer("sort_order").notNull().default(0),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true }),
},
(table) => [index("training_lessons_published_idx").on(table.published)],
);
/** Attachment metadata; the file itself is stored under `UPLOAD_DIR`. */
export const trainingResources = pgTable(
"training_resources",
{
id: text("id").primaryKey(),
lessonId: text("lesson_id")
.notNull()
.references(() => trainingLessons.id, { onDelete: "cascade" }),
filename: text("filename").notNull(),
mimeType: text("mime_type").notNull(),
sizeBytes: integer("size_bytes").notNull(),
/** Random on-disk name; never derived from user input. */
storedName: text("stored_name").notNull(),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => [index("training_resources_lesson_idx").on(table.lessonId)],
);
/* ------------------------------------------------ events & photo folders */
/** How an assigned person takes part in an event. */
export const EVENT_PHOTOGRAPHER_ROLES = [
"photographer",
"second_shooter",
"editor",
] as const;
export type EventPhotographerRole =
(typeof EVENT_PHOTOGRAPHER_ROLES)[number];
/** What a folder is for; `mixed` is the honest default for ad-hoc uploads. */
export const EVENT_FOLDER_KINDS = ["originals", "edited", "mixed"] as const;
export type EventFolderKind = (typeof EVENT_FOLDER_KINDS)[number];
/** `raw` = camera original; `image` = browser-renderable JPEG/PNG/WebP/etc. */
export const EVENT_PHOTO_KINDS = ["raw", "image"] as const;
export type EventPhotoKind = (typeof EVENT_PHOTO_KINDS)[number];
/**
* A one-off coverage event (wedding, portrait session, outreach night). This is
* deliberately a lighter table than the full J-phase event model: it exists so
* photographers can be assigned and share deliverables, and does not yet create
* scheduling slots or go through the publish/confirm pipeline.
*/
export const events = pgTable(
"events",
{
id: text("id").primaryKey(),
title: text("title").notNull(),
/** Free-form: wedding, portrait, service, outreach… */
eventType: text("event_type").notNull().default("photoshoot"),
startsAt: timestamp("starts_at", { mode: "date", withTimezone: true }).notNull(),
endsAt: timestamp("ends_at", { mode: "date", withTimezone: true }),
location: text("location"),
/** Shot brief / what to capture, shown on the event page. */
description: text("description"),
createdBy: text("created_by").references(() => users.id, {
onDelete: "set null",
}),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true }),
},
(table) => [
index("events_starts_at_idx").on(table.startsAt),
index("events_created_by_idx").on(table.createdBy),
],
);
/**
* Who may see and contribute to an event. The UNIQUE (event, user) key means a
* person holds one role per event; re-assigning updates the role rather than
* creating a duplicate.
*/
export const eventPhotographers = pgTable(
"event_photographers",
{
eventId: text("event_id")
.notNull()
.references(() => events.id, { onDelete: "cascade" }),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
role: text("role", { enum: EVENT_PHOTOGRAPHER_ROLES })
.notNull()
.default("photographer"),
assignedBy: text("assigned_by").references(() => users.id, {
onDelete: "set null",
}),
assignedAt: timestamp("assigned_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => [
primaryKey({ name: "event_photographers_pk", columns: [table.eventId, table.userId] }),
index("event_photographers_user_idx").on(table.userId),
],
);
/** A named folder inside an event: "Originals", "Edited selects", … */
export const eventFolders = pgTable(
"event_folders",
{
id: text("id").primaryKey(),
eventId: text("event_id")
.notNull()
.references(() => events.id, { onDelete: "cascade" }),
name: text("name").notNull(),
kind: text("kind", { enum: EVENT_FOLDER_KINDS })
.notNull()
.default("originals"),
createdBy: text("created_by").references(() => users.id, {
onDelete: "set null",
}),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => [
uniqueIndex("event_folders_event_name_idx").on(table.eventId, table.name),
index("event_folders_event_idx").on(table.eventId),
],
);
/**
* Photo metadata. Bytes live under `UPLOAD_DIR/events/<eventId>/`; only this
* row is in Postgres. `checksum` is the SHA-256 of the bytes and is unique per
* folder, so re-uploading the same frame is a no-op instead of a duplicate.
* `storedName` is a generated relative path, never user input.
*/
export const eventPhotos = pgTable(
"event_photos",
{
id: text("id").primaryKey(),
folderId: text("folder_id")
.notNull()
.references(() => eventFolders.id, { onDelete: "cascade" }),
uploaderId: text("uploader_id")
.notNull()
.references(() => users.id, { onDelete: "restrict" }),
filename: text("filename").notNull(),
mimeType: text("mime_type").notNull(),
sizeBytes: integer("size_bytes").notNull(),
storedName: text("stored_name").unique().notNull(),
checksumSha256: text("checksum_sha256").notNull(),
kind: text("kind", { enum: EVENT_PHOTO_KINDS }).notNull(),
/** Last saved adjustment recipe (JSON); the original is never overwritten. */
editJson: text("edit_json"),
/** Generated full-resolution JPEG. Null until the first edit is saved. */
editedStoredName: text("edited_stored_name"),
editedSizeBytes: integer("edited_size_bytes"),
editedAt: timestamp("edited_at", { mode: "date", withTimezone: true }),
editedBy: text("edited_by").references(() => users.id, {
onDelete: "set null",
}),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => [
uniqueIndex("event_photos_folder_checksum_idx").on(
table.folderId,
table.checksumSha256,
),
index("event_photos_folder_idx").on(table.folderId, table.createdAt),
],
);
/* ------------------------------------------------------- event videos */
/** Processing state for an uploaded event video. */
export const EVENT_VIDEO_STATUSES = [
"processing",
"ready",
"failed",
] as const;
export type EventVideoStatus = (typeof EVENT_VIDEO_STATUSES)[number];
/** `team` is private; `unlisted` is link-only; `public` can be discovered. */
export const EVENT_VIDEO_VISIBILITIES = [
"team",
"unlisted",
"public",
] as const;
export type EventVideoVisibility =
(typeof EVENT_VIDEO_VISIBILITIES)[number];
/**
* Event video metadata. The camera original is written to the configured NFS
* archive; the browser derivative and poster live under `UPLOAD_DIR/videos`.
* `trim_start_ms` / `trim_end_ms` are a non-destructive recipe applied when
* the web MP4 is rendered, so the original is never changed.
*/
export const eventVideos = pgTable(
"event_videos",
{
id: text("id").primaryKey(),
eventId: text("event_id")
.notNull()
.references(() => events.id, { onDelete: "cascade" }),
uploaderId: text("uploader_id")
.notNull()
.references(() => users.id, { onDelete: "restrict" }),
title: text("title").notNull(),
description: text("description"),
filename: text("filename").notNull(),
mimeType: text("mime_type").notNull(),
/** bigint: a 4 GB camera video does not fit a signed 32-bit integer. */
sizeBytes: bigint("size_bytes", { mode: "number" }).notNull(),
checksumSha256: text("checksum_sha256").notNull(),
/** Path relative to `<archivePath>/<archiveFolder>`, e.g. videos/…/original.mp4. */
originalStoredName: text("original_stored_name").unique().notNull(),
/** The archive folder in use at upload time, so a later settings change cannot orphan it. */
archiveFolder: text("archive_folder").notNull(),
durationMs: integer("duration_ms"),
width: integer("width"),
height: integer("height"),
trimStartMs: integer("trim_start_ms").notNull().default(0),
trimEndMs: integer("trim_end_ms"),
webStoredName: text("web_stored_name"),
posterStoredName: text("poster_stored_name"),
status: text("status", { enum: EVENT_VIDEO_STATUSES })
.notNull()
.default("processing"),
visibility: text("visibility", { enum: EVENT_VIDEO_VISIBILITIES })
.notNull()
.default("team"),
errorMessage: text("error_message"),
processedAt: timestamp("processed_at", { mode: "date", withTimezone: true }),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => [
uniqueIndex("event_videos_event_checksum_idx").on(
table.eventId,
table.checksumSha256,
),
index("event_videos_event_created_idx").on(
table.eventId,
table.createdAt,
),
index("event_videos_status_idx").on(table.status),
],
);
/* ---------------------------------------------------- announcements */
/**
* Team announcements authored by admins/coordinators (`content.author`).
* Plain text for now (the rich-text editor is F1); drafts are hidden from
* volunteers and can be published/unpublished at any time.
*/
export const announcements = pgTable(
"announcements",
{
id: text("id").primaryKey(),
title: text("title").notNull(),
body: text("body").notNull().default(""),
published: boolean("published").notNull().default(false),
createdBy: text("created_by").references(() => users.id, {
onDelete: "set null",
}),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true }),
},
(table) => [
index("announcements_published_created_idx").on(
table.published,
table.createdAt,
),
],
);
/* ------------------------------------------ coverage (swap) requests */
export const COVERAGE_REQUEST_STATUSES = [
"pending",
"approved",
"declined",
"cancelled",
] as const;
export type CoverageRequestStatus =
(typeof COVERAGE_REQUEST_STATUSES)[number];
/**
* A volunteer asking for their seat to be released, with an optional
* replacement chosen by a coordinator. The assignment stays live until the
* request is approved, so a pending request never silently opens a hole.
*
* At most one pending request per assignment; resolved rows remain as history.
*/
export const coverageRequests = pgTable(
"coverage_requests",
{
id: text("id").primaryKey(),
assignmentId: text("assignment_id")
.notNull()
.references(() => assignments.id, { onDelete: "cascade" }),
requestedBy: text("requested_by")
.notNull()
.references(() => users.id, { onDelete: "restrict" }),
reason: text("reason"),
status: text("status", { enum: COVERAGE_REQUEST_STATUSES })
.notNull()
.default("pending"),
replacementUserId: text("replacement_user_id").references(() => users.id, {
onDelete: "set null",
}),
resolvedBy: text("resolved_by").references(() => users.id, {
onDelete: "set null",
}),
resolvedAt: timestamp("resolved_at", { mode: "date", withTimezone: true }),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => [
uniqueIndex("coverage_requests_pending_assignment_idx")
.on(table.assignmentId)
.where(sql`${table.status} = 'pending'`),
index("coverage_requests_status_idx").on(table.status, table.createdAt),
index("coverage_requests_requester_idx").on(table.requestedBy),
],
);
/* ------------------------------------------------------------ run sheet */
/**
* One run sheet per service instance (PK = instance). Holds the service-wide
* header: speaker, message title, stream/slides links, and free notes. Items
* live in `run_sheet_items`; checklists in `service_checklist_items`.
*/
export const serviceRunSheets = pgTable("service_run_sheets", {
serviceInstanceId: text("service_instance_id")
.primaryKey()
.references(() => serviceInstances.id, { onDelete: "cascade" }),
speaker: text("speaker"),
sermonTitle: text("sermon_title"),
streamUrl: text("stream_url"),
slidesUrl: text("slides_url"),
notes: text("notes"),
updatedBy: text("updated_by").references(() => users.id, {
onDelete: "set null",
}),
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true }),
});
/**
* An ordered cue in the service. `timeLabel` is free text ("10:58") so a
* coordinator can write the booth sheet exactly as the service runs.
*/
export const runSheetItems = pgTable(
"run_sheet_items",
{
id: text("id").primaryKey(),
serviceInstanceId: text("service_instance_id")
.notNull()
.references(() => serviceInstances.id, { onDelete: "cascade" }),
sortOrder: integer("sort_order").notNull().default(0),
timeLabel: text("time_label"),
title: text("title").notNull(),
owner: text("owner"),
notes: text("notes"),
},
(table) => [
index("run_sheet_items_instance_idx").on(
table.serviceInstanceId,
table.sortOrder,
),
],
);
/** Checklist phase: before the service starts, or after it ends. */
export const CHECKLIST_PHASES = ["pre", "post"] as const;
export type ChecklistPhase = (typeof CHECKLIST_PHASES)[number];
/**
* Per-instance checklist. Rows are copied from a default template the first
* time the run sheet is opened, then owned by the instance so a coordinator can
* add or remove steps for a special service without editing a global template.
*/
export const serviceChecklistItems = pgTable(
"service_checklist_items",
{
id: text("id").primaryKey(),
serviceInstanceId: text("service_instance_id")
.notNull()
.references(() => serviceInstances.id, { onDelete: "cascade" }),
phase: text("phase", { enum: CHECKLIST_PHASES }).notNull().default("pre"),
sortOrder: integer("sort_order").notNull().default(0),
label: text("label").notNull(),
doneAt: timestamp("done_at", { mode: "date", withTimezone: true }),
doneBy: text("done_by").references(() => users.id, { onDelete: "set null" }),
},
(table) => [
uniqueIndex("service_checklist_instance_label_idx").on(
table.serviceInstanceId,
table.phase,
table.label,
),
index("service_checklist_instance_idx").on(
table.serviceInstanceId,
table.phase,
table.sortOrder,
),
],
);
/* ------------------------------------------------ coverage intake form */
export const COVERAGE_INTAKE_STATUSES = [
"new",
"scheduled",
"declined",
] as const;
export type CoverageIntakeStatus =
(typeof COVERAGE_INTAKE_STATUSES)[number];
/**
* A media-coverage request from a ministry leader or member of the church.
* Submitted from the public `/request-coverage` form, reviewed by a
* coordinator, and converted into an event (which already carries the
* photographer assignment and file-sharing workflow).
*/
export const coverageIntakes = pgTable(
"coverage_intakes",
{
id: text("id").primaryKey(),
requesterName: text("requester_name").notNull(),
requesterEmail: text("requester_email").notNull(),
requesterPhone: text("requester_phone"),
ministry: text("ministry"),
title: text("title").notNull(),
eventType: text("event_type").notNull().default("coverage"),
startsAt: timestamp("starts_at", { mode: "date", withTimezone: true })
.notNull(),
endsAt: timestamp("ends_at", { mode: "date", withTimezone: true }),
location: text("location"),
description: text("description"),
status: text("status", { enum: COVERAGE_INTAKE_STATUSES })
.notNull()
.default("new"),
createdEventId: text("created_event_id").references(() => events.id, {
onDelete: "set null",
}),
reviewedBy: text("reviewed_by").references(() => users.id, {
onDelete: "set null",
}),
reviewedAt: timestamp("reviewed_at", { mode: "date", withTimezone: true }),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => [
index("coverage_intakes_status_idx").on(table.status, table.createdAt),
index("coverage_intakes_starts_idx").on(table.startsAt),
],
);
/* ------------------------------------------------------------- relations */
/**
@@ -771,6 +1447,24 @@ export const schema = {
userSkills,
skillAssessments,
growthGoals,
notifications,
usedTokens,
usedMagicTokens,
notificationRules,
appSettings,
trainingLessons,
trainingResources,
events,
eventPhotographers,
eventFolders,
eventPhotos,
eventVideos,
announcements,
coverageRequests,
serviceRunSheets,
runSheetItems,
serviceChecklistItems,
coverageIntakes,
};
export type Schema = typeof schema;