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=requireStoney 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:
- Pick a table — Select from your schema
- Choose what to measure — Count, sum, average, min, max
- Add conditions — Filter by column values, relationships, dates
- 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 < 0Expectation: 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:
| Step | You Choose | Example |
|---|---|---|
| Table | orders | — |
| Measure | Count rows | SELECT COUNT(*) |
| Condition | customer_id not in customers.id | WHERE customer_id NOT IN (...) |
| Expectation | Equals 0 | Check passes if result is 0 |
Click Validate to test the query before saving.
Scheduling
| Schedule | When It Runs |
|---|---|
| Manual | Only when you click “Run” |
| Hourly | Every hour |
| Daily | Every day at midnight UTC |
| Weekly | Every Monday at midnight UTC |
Failed checks appear in the dashboard and can trigger alerts.
Severity
| Level | Behavior |
|---|---|
| Error | Blocks CI, sends alert |
| Warning | Sends alert only |
Use Error for critical invariants (orphaned records, data corruption).
Use Warning for soft limits (stale data, cleanup reminders).