In the database | laravel-health-go | Spatie       

 SPATIE  

laravel-health-go
=================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-health-go](https://spatie.be/docs/laravel-health-go/v1)  Storing-results  In the database

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-health-go/v1) 

  In the database    
- [ Introduction ](https://spatie.be/docs/laravel-health-go/v1/introduction)
- [ Requirements ](https://spatie.be/docs/laravel-health-go/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-health-go/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-health-go/v1/questions-issues)
- [ About us ](https://spatie.be/docs/laravel-health-go/v1/about-us)
- [ Testing ](https://spatie.be/docs/laravel-health-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-health-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-health-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-health-go/v1/support-us)

Usage
-----

- [ Registering your first check ](https://spatie.be/docs/laravel-health-go/v1/basic-usage/registering-your-first-check)
- [ Creating custom checks ](https://spatie.be/docs/laravel-health-go/v1/basic-usage/creating-custom-checks)
- [ Manually running checks ](https://spatie.be/docs/laravel-health-go/v1/basic-usage/manually-running-checks)
- [ Conditionally running or modifying checks ](https://spatie.be/docs/laravel-health-go/v1/basic-usage/conditionally-running-or-modifying-checks)
- [ Endpoints ](https://spatie.be/docs/laravel-health-go/v1/basic-usage/endpoints)
- [ Pausing and resuming checks ](https://spatie.be/docs/laravel-health-go/v1/basic-usage/pausing-and-resuming-checks)
- [ Registering the same check multiple times ](https://spatie.be/docs/laravel-health-go/v1/basic-usage/registering-the-same-check-multiple-times)
- [ Testing ](https://spatie.be/docs/laravel-health-go/v1/basic-usage/testing)

Storing results
---------------

- [ General ](https://spatie.be/docs/laravel-health-go/v1/storing-results/general)
- [ In the database ](https://spatie.be/docs/laravel-health-go/v1/storing-results/in-the-database)
- [ In cache ](https://spatie.be/docs/laravel-health-go/v1/storing-results/in-cache)
- [ In a JSON file ](https://spatie.be/docs/laravel-health-go/v1/storing-results/in-a-json-file)
- [ Not storing results ](https://spatie.be/docs/laravel-health-go/v1/storing-results/not-storing-results)

Configuring notifications
-------------------------

- [ General ](https://spatie.be/docs/laravel-health-go/v1/configuring-notifications/general)
- [ Via mail ](https://spatie.be/docs/laravel-health-go/v1/configuring-notifications/via-mail)
- [ Via Slack ](https://spatie.be/docs/laravel-health-go/v1/configuring-notifications/via-slack)
- [ Via Microsoft Teams ](https://spatie.be/docs/laravel-health-go/v1/configuring-notifications/via-teams)
- [ Via Oh Dear ](https://spatie.be/docs/laravel-health-go/v1/configuring-notifications/via-oh-dear)

Available checks
----------------

- [ Overview ](https://spatie.be/docs/laravel-health-go/v1/available-checks/overview)
- [ Cache ](https://spatie.be/docs/laravel-health-go/v1/available-checks/cache)
- [ Debug mode ](https://spatie.be/docs/laravel-health-go/v1/available-checks/debug-mode)
- [ Environment ](https://spatie.be/docs/laravel-health-go/v1/available-checks/environment)
- [ Database connection count ](https://spatie.be/docs/laravel-health-go/v1/available-checks/db-connection-count)
- [ Database connection ](https://spatie.be/docs/laravel-health-go/v1/available-checks/db-connection)
- [ Database size ](https://spatie.be/docs/laravel-health-go/v1/available-checks/db-size-check)
- [ Database table size ](https://spatie.be/docs/laravel-health-go/v1/available-checks/db-table-size-check)
- [ CPU load ](https://spatie.be/docs/laravel-health-go/v1/available-checks/cpu-load)
- [ Used disk space ](https://spatie.be/docs/laravel-health-go/v1/available-checks/used-disk-space)
- [ Ping ](https://spatie.be/docs/laravel-health-go/v1/available-checks/ping)
- [ Redis memory usage ](https://spatie.be/docs/laravel-health-go/v1/available-checks/redis-memory-usage)
- [ Redis ](https://spatie.be/docs/laravel-health-go/v1/available-checks/redis)
- [ Flare error count ](https://spatie.be/docs/laravel-health-go/v1/available-checks/flare-error-count)
- [ Meilisearch ](https://spatie.be/docs/laravel-health-go/v1/available-checks/meilisearch)
- [ Reverb ](https://spatie.be/docs/laravel-health-go/v1/available-checks/reverb)
- [ Cached config, routes, and events ](https://spatie.be/docs/laravel-health-go/v1/available-checks/cached-config-routes-and-events)
- [ Horizon ](https://spatie.be/docs/laravel-health-go/v1/available-checks/horizon)
- [ Security advisories ](https://spatie.be/docs/laravel-health-go/v1/available-checks/security-advisories)
- [ Queue ](https://spatie.be/docs/laravel-health-go/v1/available-checks/queue)
- [ Schedule ](https://spatie.be/docs/laravel-health-go/v1/available-checks/schedule)
- [ Backups ](https://spatie.be/docs/laravel-health-go/v1/available-checks/backups)

Viewing results
---------------

- [ General ](https://spatie.be/docs/laravel-health-go/v1/viewing-results/general)
- [ On the CLI ](https://spatie.be/docs/laravel-health-go/v1/viewing-results/on-the-cli)
- [ On a webpage ](https://spatie.be/docs/laravel-health-go/v1/viewing-results/on-a-webpage)
- [ As JSON ](https://spatie.be/docs/laravel-health-go/v1/viewing-results/as-json)

Security
--------

- [ Using secret token ](https://spatie.be/docs/laravel-health-go/v1/security/using-secret-token)

 In the database
===============

###  On this page 

1. [ Customizing the model ](#content-customizing-the-model)

Use `DatabaseStore` to keep result history. Add the `CreateHistoryTable` migration as described in [installation](../installation-setup).

```
store := health.DatabaseStore("")
store.KeepHistory = 7*24*time.Hour
cfg.Stores = []health.ResultStore{store}
```

An empty connection uses the default database. Each complete run is stored atomically as JSON in one `health_check_result_history_items` row. This differs from PHP's per-check history schema. The default retention is five days. Saving prunes rows with `created_at` older than retention within the same transaction. Set retention to zero to disable pruning.

Customizing the model
-----------------------------------------------------------------------------------------------------------------------

Use `ModelStore[YourModel]` with `Encode` and `Decode` functions. Your model owns the table name and fields. Add an application migration for it. Include an `id` for latest-result ordering and `created_at` when using pruning. Laravel handles model timestamps.

```
store := health.ModelStore[YourModel]{
    Connection: "reporting",
    KeepHistory: 24*time.Hour,
    Encode: encodeSnapshot,
    Decode: decodeSnapshot,
}
```

Both reads and writes go through your model. `Encode` converts a snapshot into the model and `Decode` converts it back. For a schema with different ordering or pruning rules, implement `ResultStore` directly.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
