Frozen CRM schema (4.20) and public links
A single list of units. Builder_OS_CRM_Schema::UNITS registers the ten versioned schema units: core (contacts, companies, fields, tags, segments, pipelines, deals, activities, tasks and their task_* tables, files, consents, suppression, campaigns, sends, email events and links), appt (appointments), msg (conversations and messages), auto (automations), bc (broadcasts), ap (Autopilot), ai (AI assistant), reviews, ident (Messenger and Instagram identities) and carts. Each one is a class with DB_VERSION, DB_OPTION, sql() and tables(). With that there is an install_all(), a verify() (a dbDelta dry run per unit: empty means no drift, plus the tables that aren’t InnoDB and utf8mb4), and uninstalling and deleting network sites come from the same list: a new table is registered in one place. wp bos crm status returns the schema key with the result.
What the names that are not renamed mean. runs and run_steps are the executions and steps of automations (bos_crm_automations); bc_recipients, the recipients of a broadcast; ap_actions and ap_contacts, the proposed actions and the per-contact state of the Autopilot; files, task attachments; links, the tracked links of campaigns and automations. They are not renamed: they are cosmetic and renaming risks forgotten references.
Conventions frozen for 1.0.
- Name
bos_crm_<plural>;id bigint(20) unsigned AUTO_INCREMENT; no foreign keys or ENUM (integrity is handled in code). - Dates
*_at datetimein UTC (the site’s time zone only when displaying). Money in*_cents bigintpluscurrency char(3). Flagstinyint(1) unsigned. - JSON in
longtextnamedcustom,data,rules,stats,evidenceoroptions. Statuses in lowercase ASCII,varchar(8–16). - Every
CREATE TABLEends withBuilder_OS_Schema::options()(InnoDB and utf8mb4 explicit). - Every change is a numbered step of its unit, idempotent and resumable. After 1.0 you only add; anything destructive is done in two versions.
Core schema 5 (safe migration on a live site). Adds activities.ref_created (ref_type, ref_id, created_at) and activities.deal_created (deal_id, created_at) (the latter replaces deal_id, which is dropped), deals.company_id and links.campaign_id and links.automation_id. Tables that aren’t InnoDB and utf8mb4 are converted (so they support emojis in messages), one by one. Every step can be repeated with no effect. Rules so a live site doesn’t suffer:
- Never on a public visit. Step 5 (indexes and table conversion) is “heavy” and only runs from cron, an administrator’s dashboard (not
admin-ajax) or WP-CLI (Builder_OS_CRM_Schema::heavy_allowed(), filterbuilder_os_crm_schema_heavy_ok). A public visit (chat, cart capture, WhatsApp attribution, a public REST route) that reachesmaybe_install()with the tables already in place doesn’t run a singleALTER: the schema stays at version 4 until cron, an administrator or WP-CLI does it. - A single installer.
install()takes an atomic lock (add_optionofbuilder_os_crm_schema_lock, with a 5-minute expiry and taking over an expired lock with a conditionalUPDATE) before touching anything; if another visit holds it, it neither waits nor repeats. The retry flag (bos_crm_schema_retry, 5 minutes) is set before the firstALTER, so if PHP dies halfway through a conversion the following visits don’t start from zero. - Lock waits. Each
ALTERruns with a shortlock_wait_timeout(10 s; filterbuilder_os_crm_schema_lock_wait). A 1205 (wait) or 1213 (deadlock) error is transient: the table stays pending, is not logged as a failure, the schema does not bump its version and it is retried. A flag saved because of a lock wait is discarded and retried. A table that can’t be converted for another reason is logged inbuilder_os_crm_schema_issues(which is deleted on uninstall) andverify()shows it; it doesn’t block the rest. - A new messages table creates its unique index
provider_msgwith a prefix (provider_id(175)) to fit within the 767 bytes of MySQL 5.6 and MariaDB 10.1 with utf8mb4; tables already created keep the full index.
Public appointment and review links (credentials). New format: <id>.<token>.<caducidad en base 36>.<firma> (Builder_OS_CRM_Token).
- The token is 32 base62 characters (
^[A-Za-z0-9]{32}$, about 190 bits) drawn fromrandom_byteswith rejection sampling: the same format 4.19 already accepts. The new row is marked with thetoken_vcolumn (tinyint,2= 4-part links;0= rows created by 4.19, which doesn’t know the column) inbos_crm_appointmentsandbos_crm_review_requests. The token format doesn’t tell versions apart. - The signature is a 128-bit HMAC-SHA256 over scope (
apptorrev), id, token and expiry. Its key comes from thewp-config.phpsalts: someone who can only read the database (a backup, an injection in another plugin) cannot forge links. - Constant-time comparison, signed expiry, and the id ties each credential to a single row (that of one appointment or contact doesn’t open another). It always gives the same response to any failure, with no hints.
- Deterministic expiry. Appointment: end of the appointment + 30 days (filter
builder_os_crm_appt_link_days); opening the page doesn’t renew the link, so a past appointment’s link dies. Review: creation + 90 days (builder_os_crm_review_link_days). The lesser of the signed expiry and the row’s expiry rules; the reviews page shows “This link has expired” (410). - Versions. A
token_v 2row requires the 4-part link and rejects the 3-part one. Atoken_v 0row (from 4.19) keeps accepting the 3-part link (<id>.<token>.<firma de 16 hex>) within its period and rejects the 4-part one. An anonymized contact regenerates their review token astoken_v 2. - The appointment and review pages send
Referrer-Policy: no-referrerandX-Robots-Tag: noindex. - Appointment reminder and review request SMS messages store in the messages table the text sent, with the link working (the queue reads it from there to send it): the link expires as stated and the table is only seen by those with CRM permission. Don’t copy it into logs or exports outside the CRM.
- Carts: the link already carried a signed expiry with the salts; the token is now generated with
random_intand compared exactly. - Rotating the salts or restoring on another site invalidates 4-part links already sent (see “Salt rotation” in chapter 26) and downgrading to 4.19 changes which links open (see the rollback procedure).
For the AI (chapter 25) and the checklist. A new CRM table: sql() with Builder_OS_Schema::options(), an entry in UNITS, verify() with no drift and bos-test-crm-schema green. A new public link: Builder_OS_CRM_Token::make() and parse(), never a plain token in the link without a signature.