›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-customer-health
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Product events
  • Features and milestones
  • Onboarding
  • Health scores
  • Summaries and tenancy

Operations

  • Querying customer health
  • Queueing events
  • Recomputing scores
  • Retention and erasure
  • Production operations

Reference

  • Configuration
  • Public API
  • Events
  • Console commands
  • Database storage
  • Testing
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Product events
  • Features and milestones
  • Onboarding
  • Health scores
  • Summaries and tenancy

Operations

  • Querying customer health
  • Queueing events
  • Recomputing scores
  • Retention and erasure
  • Production operations

Reference

  • Configuration
  • Public API
  • Events
  • Console commands
  • Database storage
  • Testing
  • Troubleshooting

byrcsc/laravel-customer-health · 1.x

Database storage.

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"

Events table

Default name: customer_health_events.

ColumnShape
idAuto-incrementing primary key
subject_typeString morph type
subject_idString, length 191
actor_typeNullable string morph type
actor_idNullable string, length 191
nameEvent name string
featureFeature name string
propertiesJSON
occurred_atTimestamp with timezone
created_atTimestamp 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.

Milestones table

Default name: customer_health_milestones.

ColumnShape
idAuto-incrementing primary key
subject_typeString morph type
subject_idString, length 191
nameEvent or onboarding completion name
actor_typeNullable string morph type
actor_idNullable string, length 191
occurred_atTimestamp with timezone
created_atTimestamp 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.

Scores table

Default name: customer_health_scores.

ColumnShape
idAuto-incrementing primary key
subject_typeString morph type
subject_idString, length 191
scoreScore name string
valueUnsigned tiny integer
stateState name string
breakdownJSON signal breakdown
computed_atTimestamp 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.

Summaries table

Default name: customer_health_summaries.

ColumnShape
idAuto-incrementing primary key
summary_keyUnique 64-character SHA-256 key
tenant_idNullable string
subject_typeString morph type
subject_idString, length 191
scoreScore name string
valueUnsigned tiny integer
stateState name string
computed_atTimestamp with timezone
created_at, updated_atTimestamp 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.

Connection resolution

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.

UTC datetime cast

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.

Write boundaries

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.

What to read next

  • Configuration for table and connection settings.
  • Retention and erasure for row lifecycle.
  • Testing to assert stored rows and UTC values.
PreviousConsole commandsNextTesting
View source

On this page

  1. Events table
  2. Milestones table
  3. Scores table
  4. Summaries table
  5. Connection resolution
  6. UTC datetime cast
  7. Write boundaries
  8. What to read next