Skip to Content
SQL Invariants

SQL Invariants

Verify database-level guarantees.


Example

checkType: sql says: "No orphaned orders" steps: - sql: query: | SELECT COUNT(*) as count FROM orders WHERE customer_id NOT IN (SELECT id FROM customers) url_env: "DATABASE_URL" expect: rows: - count: 0

Store your connection string in Settings → Secrets.


Common Patterns

Referential integrity:

SELECT COUNT(*) FROM order_items oi LEFT JOIN products p ON oi.product_id = p.id WHERE p.id IS NULL

Business rules:

SELECT COUNT(*) FROM inventory WHERE quantity < 0

Read-Only Access

Use a read-only database user:

CREATE USER stoney_readonly WITH PASSWORD '...'; GRANT SELECT ON ALL TABLES IN SCHEMA public TO stoney_readonly;

Supported Databases

PostgreSQL, MySQL, SQLite, SQL Server

Last updated on