Vespertide Database Schema Definition
Declarative database schema management. Define tables in JSON, generate typed migrations and SQL.
CRITICAL: Always validate your model against the JSON Schema before committing. Use
$schemain every model file for IDE validation.
Schema Validation (MANDATORY)
Every model file MUST include the $schema field:
{
"$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json",
"name": "table_name",
"columns": []
}
Before saving any model:
- •Ensure
$schemaURL is present - •Verify IDE shows no validation errors
- •Run
vespertide diffto check for parsing errors
The schema URL provides:
- •Real-time validation in VS Code, WebStorm, etc.
- •Autocompletion for all fields
- •Type checking for column types and constraints
Post-Edit Validation (MANDATORY)
After EVERY edit to a model file, ALWAYS run these checks:
# 1. Check for parsing errors and schema violations vespertide diff # 2. Preview generated SQL to verify correctness vespertide sql
Verify the output:
- •
vespertide diffshows expected changes (no unexpected additions/removals) - •
vespertide sqlgenerates valid SQL for your target database - •IDE shows no red squiggles (schema validation errors)
- •All required fields (
name,type,nullable) are present
Only proceed to vespertide revision after verification passes.
Installation
cargo install vespertide-cli
CLI Commands
| Command | Description |
|---|---|
vespertide init | Initialize project with vespertide.json |
vespertide new <name> | Create model template with $schema |
vespertide diff | Show pending changes |
vespertide sql | Preview SQL for next migration |
vespertide sql --backend mysql | SQL for specific backend (postgres/mysql/sqlite) |
vespertide revision -m "msg" | Create migration file |
vespertide status | Show project status |
vespertide log | List applied migrations |
vespertide export --orm seaorm | Export to ORM code |
Exported ORM Files (DO NOT EDIT)
CRITICAL: Files generated by
vespertide exportare AUTO-GENERATED. Never modify them manually.
Rules
- •Never manually edit exported files (SeaORM entities, SQLAlchemy models, etc.)
- •Always regenerate by running
vespertide export --orm <orm_name> - •Edit source models in
models/*.jsoninstead, then re-export
Workflow
# 1. Edit your model files (models/*.json) # 2. Regenerate ORM code vespertide export --orm seaorm # 3. Never touch the generated files after this
Migration Files (DO NOT EDIT)
CRITICAL: Migration files are AUTO-GENERATED. Never create or modify them manually.
Rules
- •Always use
vespertide revision -m "message"to create migrations - •Never manually create migration JSON files
- •Never manually edit migration JSON files
- •Only exception: Adding
fill_withvalues when prompted
When fill_with is Required
When adding a NOT NULL column to an existing table without a default value, the CLI will prompt for a fill_with value. This is the ONLY case where you may need to edit the migration:
{
"type": "add_column",
"table": "user",
"column": {
"name": "status",
"type": "text",
"nullable": false
},
"fill_with": "'active'"
}
The fill_with value is used to backfill existing rows during migration.
Workflow
# 1. Edit your model files (models/*.json) # 2. Check what changed vespertide diff # 3. Preview SQL vespertide sql # 4. Create migration (auto-generated) vespertide revision -m "add status column" # 5. If prompted for fill_with, provide a value # 6. Never touch migration files after this
Model Structure
{
"$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json",
"name": "table_name",
"description": "Optional table description",
"columns": [
/* ColumnDef[] */
]
}
Note:
constraintsfield is optional. Only add it when you need CHECK constraints.
Required Fields
| Field | Type | Description |
|---|---|---|
name | string | Table name (snake_case) |
columns | array | Column definitions |
Optional Fields
| Field | Type | Description |
|---|---|---|
description | string | Table documentation |
constraints | array | Table-level constraints (only for CHECK) |
Column Definition
Required Fields
{
"name": "column_name",
"type": "ColumnType",
"nullable": false
}
Optional Fields
| Field | Type | Description |
|---|---|---|
default | string | boolean | number | Default value |
comment | string | Column documentation |
primary_key | boolean | object | Inline primary key |
unique | boolean | string | string[] | Inline unique constraint |
index | boolean | string | string[] | Inline index |
foreign_key | string | object | Inline foreign key |
Column Types
Simple Types (string values)
| Type | SQL | Use Case |
|---|---|---|
"small_int" | SMALLINT | Small integers (-32768 to 32767) |
"integer" | INTEGER | IDs, counts, standard integers |
"big_int" | BIGINT | Large numbers, timestamps as int |
"real" | REAL | Single precision float |
"double_precision" | DOUBLE PRECISION | Double precision float |
"text" | TEXT | Variable-length strings |
"boolean" | BOOLEAN | True/false flags |
"date" | DATE | Date only (no time) |
"time" | TIME | Time only (no date) |
"timestamp" | TIMESTAMP | Date/time without timezone |
"timestamptz" | TIMESTAMPTZ | Date/time with timezone |
"interval" | INTERVAL | Time duration |
"bytea" | BYTEA | Binary data |
"uuid" | UUID | UUIDs |
"json" | JSON | JSON data (cross-database compatible) |
"inet" | INET | IPv4/IPv6 address |
"cidr" | CIDR | Network address |
"macaddr" | MACADDR | MAC address |
"xml" | XML | XML data |
Complex Types (object values)
VARCHAR
{ "kind": "varchar", "length": 255 }
CHAR
{ "kind": "char", "length": 2 }
NUMERIC/DECIMAL
{ "kind": "numeric", "precision": 10, "scale": 2 }
ENUM (STRONGLY RECOMMENDED)
String Enum:
{
"kind": "enum",
"name": "order_status",
"values": ["pending", "processing", "shipped", "delivered", "cancelled"]
}
Integer Enum:
{
"kind": "enum",
"name": "priority_level",
"values": [
{ "name": "low", "value": 0 },
{ "name": "medium", "value": 1 },
{ "name": "high", "value": 2 },
{ "name": "critical", "value": 3 }
]
}
Inline Constraints (PREFERRED)
Always define constraints directly on columns.
Guidelines Summary
MUST DO
- •Always include
$schema - •Always specify
nullable - •Index foreign key columns - Add
"index": true - •Use inline constraints
MUST NOT DO
- •Never use PascalCase for reference actions - Use
"cascade"not"Cascade" - •Never skip schema validation
- •Never add NOT NULL columns without default
- •Never manually edit exported ORM files
- •Never use
jsonbtype - Usejsoninstead