›
byrcsc/laravel-customer-health · 1.x
Reference the package tables, indexes, connections, casts, and readable Eloquent models.
Use this page when reviewing migrations, building database queries, or deciding which rows belong in retention and erasure workflows.
Publish the four migrations with:
php artisan vendor:publish --tag="customer-health-migrations"Default name: customer_health_events.
| Column | Shape |
|---|---|
id | Auto-incrementing primary key |
subject_type | String morph type |
subject_id | String, length 191 |
actor_type | Nullable string morph type |
actor_id | Nullable string, length 191 |
name | Event name string |
feature | Feature name string |
properties | JSON |
occurred_at | Timestamp with timezone |
created_at | Timestamp with timezone, current by default |
Indexes:
(subject_type, subject_id, name, occurred_at) as
ch_events_subject_name_time_idx;(name, occurred_at) as ch_events_name_time_idx; and(feature, occurred_at) as ch_events_feature_time_idx.ProductEventRecord casts properties to an array and occurred_at to UTC
CarbonImmutable. It exposes subject() and actor() morph relations and
uses MassPrunable.
Default name: customer_health_milestones.
| Column | Shape |
|---|---|
id | Auto-incrementing primary key |
subject_type | String morph type |
subject_id | String, length 191 |
name | Event or onboarding completion name |
actor_type | Nullable string morph type |
actor_id | Nullable string, length 191 |
occurred_at | Timestamp with timezone |
created_at | Timestamp with timezone, current by default |
The unique index (subject_type, subject_id, name) enforces one first
occurrence. The (name, occurred_at) index supports checklist and milestone
queries.
Milestone exposes subject() and actor() and casts occurred_at to UTC
CarbonImmutable.
Default name: customer_health_scores.
| Column | Shape |
|---|---|
id | Auto-incrementing primary key |
subject_type | String morph type |
subject_id | String, length 191 |
score | Score name string |
value | Unsigned tiny integer |
state | State name string |
breakdown | JSON signal breakdown |
computed_at | Timestamp with timezone |
The index (subject_type, subject_id, score, computed_at) supports current and
historical score reads.
HealthScoreRecord casts value to an integer, breakdown to an array, and
computed_at to UTC CarbonImmutable. toScoreResult() returns the public
value object.
Default name: customer_health_summaries.
| Column | Shape |
|---|---|
id | Auto-incrementing primary key |
summary_key | Unique 64-character SHA-256 key |
tenant_id | Nullable string |
subject_type | String morph type |
subject_id | String, length 191 |
score | Score name string |
value | Unsigned tiny integer |
state | State name string |
computed_at | Timestamp with timezone |
created_at, updated_at | Timestamp with timezone |
The summary key hashes tenant ID, subject type, subject ID, and score name. The
table also indexes (state, score) as ch_summaries_state_score_idx.
HealthSummary casts value to an integer and computed_at to UTC
CarbonImmutable. subjectIdentity() returns its morph identity without
assuming an application model connection.
Events, milestones, and scores use customer-health.connection. A null value
uses Laravel's current default connection.
Summaries use customer-health.summary_connection when it is a non-empty
string. Otherwise they fall back to the package connection.
The migrations use the same resolution as the models. Configure connections and table names before running them.
The package's datetime cast accepts a DateTimeInterface or parseable string,
converts it to UTC for storage, and returns CarbonImmutable in UTC.
This applies to event occurrence times, milestone times, score computation times, and summary computation times.
The models are readable public types. Do not use them as the normal write API.
Direct event inserts do not create milestones or dispatch events. Direct score inserts do not calculate breakdowns, serialize state transitions, update summaries, or dispatch score events.
Use CustomerHealth::track(), CustomerHealth::compute(), and
CustomerHealth::purge() to preserve those invariants.