@validate
Column-level validation constraints plus documentation and schema linting
Postgres Mysql (beta) Sqlite (beta) MssqlExample
Add validation constraints
Validation tags emit check constraints when the engine supports them and always enrich docs metadata.
Input SQL
sql
CREATE TABLE products (
id SERIAL PRIMARY KEY,
-- @validate.notEmpty
name TEXT NOT NULL,
-- @validate.range(min: 0, max: 99999)
price NUMERIC(10,2) NOT NULL
);Compiled Output
sql
ALTER TABLE "products" ADD CONSTRAINT "products_name_not_empty" CHECK (length(trim("name")) > 0);
ALTER TABLE "products" ADD CONSTRAINT "products_price_range" CHECK ("price" >= 0 AND "price" <= 99999);Tags
@validate.check
Add a CHECK constraint with a custom expression
Targets: column
Arguments:
| Name | Type | Required | Values |
|---|---|---|---|
| positional | string | Yes | — |
@validate.notEmpty
Add a CHECK constraint ensuring the column is not empty (length(trim(col)) > 0)
Targets: column
Arguments: No arguments.
@validate.range
Add a CHECK constraint ensuring the column value is within a numeric range
Targets: column
Arguments:
| Name | Type | Required | Values |
|---|---|---|---|
| min | number | Yes | — |
| max | number | Yes | — |
@validate.length
Add a CHECK constraint on string length
Targets: column
Arguments:
| Name | Type | Required | Values |
|---|---|---|---|
| min | number | No | — |
| max | number | No | — |
@validate.pattern
Add a CHECK constraint using a regex pattern (~ for Postgres, REGEXP for MySQL)
Targets: column
Arguments:Positional: string
Lint Rules
validate.require-pk
Tables should have a primary key
Default severity: warn
