Skip to Content
Database Checks

Database Checks

Run SQL queries against your database to verify data integrity. No orphaned records, no invalid states, no surprises.


Setup

1. Add your database connection

Go to Settings → Connections and add your DATABASE_URL:

postgresql://user:pass@host:5432/database?sslmode=require

Stoney connects read-only. We never modify your data.

2. Create a check

Go to DB Checks and click Add Check. The visual builder guides you:

  1. Pick a table — Select from your schema
  2. Choose what to measure — Count, sum, average, min, max
  3. Add conditions — Filter by column values, relationships, dates
  4. Set expectation — Define what “healthy” looks like

Examples

No orphaned orders

Orders should always have a valid customer.

SELECT COUNT(*) FROM orders WHERE customer_id NOT IN (SELECT id FROM customers)

Expectation: equals 0

No negative inventory

Products should never have negative stock.

SELECT COUNT(*) FROM products WHERE quantity < 0

Expectation: equals 0

All users have emails

Every user account needs an email address.

SELECT COUNT(*) FROM users WHERE email IS NULL OR email = ''

Expectation: equals 0

No stale carts

Carts older than 30 days should be cleaned up.

SELECT COUNT(*) FROM carts WHERE updated_at < NOW() - INTERVAL '30 days'

Expectation: less than 100


Visual Builder

Don’t know SQL? The visual builder generates it for you:

StepYou ChooseExample
Tableorders
MeasureCount rowsSELECT COUNT(*)
Conditioncustomer_id not in customers.idWHERE customer_id NOT IN (...)
ExpectationEquals 0Check passes if result is 0

Click Validate to test the query before saving.


Scheduling

ScheduleWhen It Runs
ManualOnly when you click “Run”
HourlyEvery hour
DailyEvery day at midnight UTC
WeeklyEvery Monday at midnight UTC

Failed checks appear in the dashboard and can trigger alerts.


Severity

LevelBehavior
ErrorBlocks CI, sends alert
WarningSends alert only

Use Error for critical invariants (orphaned records, data corruption).
Use Warning for soft limits (stale data, cleanup reminders).

Last updated on