From da1365f06001196632d0327141fc2f8a0c34d8a9 Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Sun, 15 Nov 2026 12:50:26 -0800 Subject: [PATCH] Schema v3: goals.close_at_target and alert_defs table (contract in docs) Co-Authored-By: Claude Sonnet 5.5 --- docs/ARCHITECTURE.md | 8 ++++++++ includes/Core/Installer.php | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 488479f..1970ec8 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -73,3 +73,11 @@ PHP (namespace `StreamGoals\Actions`): - `Recorder::forDonation(int $donationId): void` — called after a donation becomes `completed` (same place the rules engine is applied); matches on the donation's BASE amount (not fee cover) using the goal's enabled actions and records events. Never throws. Public/overlay: the donate form shows each enabled action as a button (amount + title); the overlay has a new `actions` widget (the menu for the active goal) and alert payloads gain `actions`: `[ {title, times} ]` read from sg_action_events (anonymous donors' actions are still shown; names stay masked). Amounts must be >= Settings::effectiveMin(). + +## Schema v3 (Installer, DB_VERSION 3) +- `sg_goals.close_at_target` TINYINT: when 1, the goal is closed to donors as soon as its raised total reaches or exceeds the target (status becomes `complete`, same as the manual "Complete" action). +- `sg_alert_defs` — owner-defined alert presentations (media from the WordPress Media Library; attachment ids, never raw URLs): + id, goal_id (0 = all goals), trigger_type `amount` | `reward`, min_minor (for `amount`: applies when the donation BASE amount >= min_minor; the highest matching min_minor wins), + action_id (for `reward`: applies when that reward triggered; a reward definition wins over an amount definition), title (admin label), + visual_id + visual_type (`image` | `video` | '' none), sound_id (audio attachment, 0 none), volume 0-100, duration_ms (how long an image/GIF stays; videos play to the end, capped), + message (template with {name} {amount} {reward}; '' = default text), enabled, sort, created_at. diff --git a/includes/Core/Installer.php b/includes/Core/Installer.php index bc95885..5ff4780 100644 --- a/includes/Core/Installer.php +++ b/includes/Core/Installer.php @@ -8,7 +8,7 @@ namespace StreamGoals\Core; */ final class Installer { - public const DB_VERSION = '2'; + public const DB_VERSION = '3'; public static function activate(): void { self::install_schema(); @@ -39,6 +39,7 @@ final class Installer { starts_at DATETIME NULL, ends_at DATETIME NULL, counts_fees TINYINT(1) NOT NULL DEFAULT 0, + close_at_target TINYINT(1) NOT NULL DEFAULT 0, created_at DATETIME NOT NULL, PRIMARY KEY (id) ) $c;" ); @@ -122,6 +123,26 @@ final class Installer { KEY status_id (status,id) ) $c;" ); + dbDelta( "CREATE TABLE {$p}alert_defs ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + goal_id BIGINT UNSIGNED NOT NULL DEFAULT 0, + trigger_type VARCHAR(8) NOT NULL DEFAULT 'amount', + min_minor BIGINT UNSIGNED NOT NULL DEFAULT 0, + action_id BIGINT UNSIGNED NOT NULL DEFAULT 0, + title VARCHAR(120) NOT NULL DEFAULT '', + visual_id BIGINT UNSIGNED NOT NULL DEFAULT 0, + visual_type VARCHAR(6) NOT NULL DEFAULT '', + sound_id BIGINT UNSIGNED NOT NULL DEFAULT 0, + volume TINYINT UNSIGNED NOT NULL DEFAULT 80, + duration_ms INT UNSIGNED NOT NULL DEFAULT 6000, + message VARCHAR(255) NOT NULL DEFAULT '', + enabled TINYINT(1) NOT NULL DEFAULT 1, + sort INT NOT NULL DEFAULT 0, + created_at DATETIME NOT NULL, + PRIMARY KEY (id), + KEY goal_enabled (goal_id,enabled) + ) $c;" ); + update_option( 'sg_db_version', self::DB_VERSION ); } }