Awesome-omni-skill vespertide
Define database schemas in JSON and generate migration plans. Use this skill when creating or modifying database models, defining tables with columns, constraints, and ENUM types for Vespertide-based projects.
git clone https://github.com/diegosouzapw/awesome-omni-skill
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data-ai/vespertide" ~/.claude/skills/diegosouzapw-awesome-omni-skill-vespertide && rm -rf "$T"
skills/data-ai/vespertide/SKILL.mdVespertide 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
in every model file for IDE validation.$schema
Schema Validation (MANDATORY)
Every model file MUST include the
field:$schema
{ "$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
URL is present$schema - Verify IDE shows no validation errors
- Run
to check for parsing errorsvespertide diff
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:
shows expected changes (no unexpected additions/removals)vespertide diff
generates valid SQL for your target databasevespertide sql- IDE shows no red squiggles (schema validation errors)
- All required fields (
,name
,type
) are presentnullable
Only proceed to
after verification passes.vespertide revision
Installation
cargo install vespertide-cli
CLI Commands
| Command | Description |
|---|---|
| Initialize project with |
| Create model template with |
| Show pending changes |
| Preview SQL for next migration |
| SQL for specific backend (postgres/mysql/sqlite) |
| Create migration file |
| Show project status |
| List applied migrations |
| Export to ORM code |
Exported ORM Files (DO NOT EDIT)
CRITICAL: Files generated by
are AUTO-GENERATED. Never modify them manually.vespertide export
Rules
- Never manually edit exported files (SeaORM entities, SQLAlchemy models, etc.)
- Always regenerate by running
vespertide export --orm <orm_name> - Edit source models in
instead, then re-exportmodels/*.json
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
to create migrationsvespertide revision -m "message" - Never manually create migration JSON files
- Never manually edit migration JSON files
- Only exception: Adding
values when promptedfill_with
When fill_with
is Required
fill_withWhen 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:
field is optional. Only add it when you need CHECK constraints.constraints
Required Fields
| Field | Type | Description |
|---|---|---|
| string | Table name (snake_case) |
| array | Column definitions |
Optional Fields
| Field | Type | Description |
|---|---|---|
| string | Table documentation |
| array | Table-level constraints (only for CHECK) |
Column Definition
Required Fields
{ "name": "column_name", "type": "ColumnType", "nullable": false }
Optional Fields
| Field | Type | Description |
|---|---|---|
| string | boolean | number | Default value |
| string | Column documentation |
| boolean | object | Inline primary key |
| boolean | string | string[] | Inline unique constraint |
| boolean | string | string[] | Inline index |
| string | object | Inline foreign key |
Column Types
Simple Types (string values)
| Type | SQL | Use Case |
|---|---|---|
| SMALLINT | Small integers (-32768 to 32767) |
| INTEGER | IDs, counts, standard integers |
| BIGINT | Large numbers, timestamps as int |
| REAL | Single precision float |
| DOUBLE PRECISION | Double precision float |
| TEXT | Variable-length strings |
| BOOLEAN | True/false flags |
| DATE | Date only (no time) |
| TIME | Time only (no date) |
| TIMESTAMP | Date/time without timezone |
| TIMESTAMPTZ | Date/time with timezone |
| INTERVAL | Time duration |
| BYTEA | Binary data |
| UUID | UUIDs |
| JSON | JSON data (cross-database compatible) |
| INET | IPv4/IPv6 address |
| CIDR | Network address |
| MACADDR | MAC address |
| XML | XML data |
Complex Types (object values)
VARCHAR (variable-length string with limit)
{ "kind": "varchar", "length": 255 }
CHAR (fixed-length string)
{ "kind": "char", "length": 2 }
NUMERIC/DECIMAL (exact precision)
{ "kind": "numeric", "precision": 10, "scale": 2 }
ENUM (STRONGLY RECOMMENDED)
Use enums instead of text columns with CHECK constraints for status fields, categories, and any fixed set of values.
String Enum (PostgreSQL native enum):
{ "kind": "enum", "name": "order_status", "values": ["pending", "processing", "shipped", "delivered", "cancelled"] }
Integer Enum (stored as INTEGER, no DB migration needed for new values):
{ "kind": "enum", "name": "priority_level", "values": [ { "name": "low", "value": 0 }, { "name": "medium", "value": 1 }, { "name": "high", "value": 2 }, { "name": "critical", "value": 3 } ] }
Why Integer Enums?
- Adding new values requires NO database migration
- Application-level enum mapping only
- Better for frequently-changing value sets
- Works identically across PostgreSQL, MySQL, SQLite
Custom Type (AVOID - last resort only)
WARNING: Avoid custom types. They break cross-database compatibility. Use built-in types or redesign your schema.
{ "kind": "custom", "custom_type": "POINT" } { "kind": "custom", "custom_type": "TSVECTOR" }
Enum Best Practices (RECOMMENDED)
When to Use Enums
| Scenario | Recommended Type |
|---|---|
| Status fields (order_status, user_status) | String enum or Integer enum |
| Categories with fixed values | String enum |
| Priority/severity levels | Integer enum |
| Roles with potential expansion | Integer enum |
| Country/currency codes (ISO) | String enum |
String Enum Example
{ "name": "status", "type": { "kind": "enum", "name": "article_status", "values": ["draft", "review", "published", "archived"] }, "nullable": false, "default": "'draft'" }
Integer Enum Example
{ "name": "role", "type": { "kind": "enum", "name": "user_role", "values": [ { "name": "guest", "value": 0 }, { "name": "user", "value": 10 }, { "name": "moderator", "value": 50 }, { "name": "admin", "value": 100 } ] }, "nullable": false, "default": 0 }
Tip: Leave gaps in integer values (0, 10, 50, 100) to allow inserting new values in between without renumbering.
Inline Constraints (PREFERRED)
Always define constraints directly on columns. This is cleaner, more readable, and the recommended pattern. Use table-level
array ONLY for composite keys or CHECK expressions.constraints
Primary Key
Simple:
{ "name": "id", "type": "integer", "nullable": false, "primary_key": true }
With auto-increment:
{ "name": "id", "type": "integer", "nullable": false, "primary_key": { "auto_increment": true } }
Unique
Simple unique:
{ "name": "email", "type": "text", "nullable": false, "unique": true }
Named unique (for composite):
{ "name": "tenant_id", "type": "integer", "nullable": false, "unique": ["uq_tenant_user"] }, { "name": "username", "type": "text", "nullable": false, "unique": ["uq_tenant_user"] }
Index
Simple index:
{ "name": "email", "type": "text", "nullable": false, "index": true }
Composite index:
{ "name": "user_id", "type": "integer", "nullable": false, "index": ["idx_user_created"] }, { "name": "created_at", "type": "timestamptz", "nullable": false, "index": ["idx_user_created"] }
Foreign Key
Object syntax (recommended):
{ "name": "user_id", "type": "integer", "nullable": false, "foreign_key": { "ref_table": "user", "ref_columns": ["id"], "on_delete": "cascade", "on_update": null }, "index": true }
Shorthand syntax:
{ "name": "user_id", "type": "integer", "nullable": false, "foreign_key": "user.id", "index": true }
Reference Actions (snake_case):
- Delete/update child rows"cascade"
- Prevent if children exist"restrict"
- Set to NULL"set_null"
- Set to default value"set_default"
- Defer check (PostgreSQL)"no_action"
Always add
on foreign key columns for query performance."index": true
Table-Level Constraints
IMPORTANT: Always prefer inline constraints (
,primary_key,unique,indexon columns). Table-levelforeign_keyis ONLY needed for CHECK expressions.constraints
When Table-Level is Required
| Scenario | Why Inline Won't Work |
|---|---|
| CHECK constraint with expression | No inline equivalent exists |
Inline Works for Everything Else
| Scenario | Inline Solution |
|---|---|
| Composite primary key | on EACH column |
| Composite unique | on each column |
| Composite index | on each column |
| Foreign key | on the column |
Syntax (CHECK only)
"constraints": [ { "type": "check", "name": "check_positive_amount", "expr": "amount > 0" }, { "type": "check", "name": "check_dates", "expr": "end_date > start_date" } ]
What NOT to Put in Table-Level
// BAD - Use inline instead "constraints": [ { "type": "primary_key", "columns": ["tenant_id", "user_id"] }, // Use: "primary_key": true on each column { "type": "unique", "columns": ["email"] }, // Use: "unique": true on column { "type": "foreign_key", "columns": ["user_id"], ... }, // Use: "foreign_key": {...} on column { "type": "index", "columns": ["created_at"] } // Use: "index": true on column ] // GOOD - Only CHECK constraints "constraints": [ { "type": "check", "name": "check_amount", "expr": "amount >= 0" } ]
Composite Primary Key Example (Inline)
{ "name": "user_role", "columns": [ { "name": "user_id", "type": "integer", "nullable": false, "primary_key": true }, { "name": "role_id", "type": "integer", "nullable": false, "primary_key": true } ] }
Both columns with
"primary_key": true creates a single composite primary key (user_id, role_id).
Default Values
| Type | Example | Notes |
|---|---|---|
| String literal | | Single quotes inside string |
| Boolean | or | Native JSON boolean |
| Integer | | Native JSON number |
| Float | | Native JSON number |
| SQL function | | No quotes around function |
| UUID generation | | PostgreSQL |
{ "name": "status", "type": "text", "nullable": false, "default": "'active'" }, { "name": "count", "type": "integer", "nullable": false, "default": 0 }, { "name": "enabled", "type": "boolean", "nullable": false, "default": true }, { "name": "created_at", "type": "timestamptz", "nullable": false, "default": "NOW()" }
Complete Examples
User Table with Enum Status
{ "$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json", "name": "user", "columns": [ { "name": "id", "type": "integer", "nullable": false, "primary_key": { "auto_increment": true } }, { "name": "email", "type": "text", "nullable": false, "unique": true, "index": true }, { "name": "name", "type": { "kind": "varchar", "length": 100 }, "nullable": false }, { "name": "status", "type": { "kind": "enum", "name": "user_status", "values": ["pending", "active", "suspended", "deleted"] }, "nullable": false, "default": "'pending'" }, { "name": "metadata", "type": "json", "nullable": true }, { "name": "created_at", "type": "timestamptz", "nullable": false, "default": "NOW()" }, { "name": "updated_at", "type": "timestamptz", "nullable": true } ] }
Order Table with Integer Enum Priority
{ "$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json", "name": "order", "columns": [ { "name": "id", "type": "uuid", "nullable": false, "primary_key": true, "default": "gen_random_uuid()" }, { "name": "customer_id", "type": "integer", "nullable": false, "foreign_key": { "ref_table": "customer", "ref_columns": ["id"], "on_delete": "restrict" }, "index": true }, { "name": "total", "type": { "kind": "numeric", "precision": 10, "scale": 2 }, "nullable": false }, { "name": "priority", "type": { "kind": "enum", "name": "order_priority", "values": [ { "name": "low", "value": 0 }, { "name": "normal", "value": 10 }, { "name": "high", "value": 20 }, { "name": "urgent", "value": 30 } ] }, "nullable": false, "default": 10 }, { "name": "status", "type": { "kind": "enum", "name": "order_status", "values": ["pending", "confirmed", "shipped", "delivered", "cancelled"] }, "nullable": false, "default": "'pending'" }, { "name": "notes", "type": "text", "nullable": true }, { "name": "created_at", "type": "timestamptz", "nullable": false, "default": "NOW()" } ], "constraints": [ { "type": "check", "name": "check_total_positive", "expr": "total >= 0" } ] }
Many-to-Many Join Table
{ "$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json", "name": "user_role", "columns": [ { "name": "user_id", "type": "integer", "nullable": false, "primary_key": true, "foreign_key": { "ref_table": "user", "ref_columns": ["id"], "on_delete": "cascade" } }, { "name": "role_id", "type": "integer", "nullable": false, "primary_key": true, "foreign_key": { "ref_table": "role", "ref_columns": ["id"], "on_delete": "cascade" }, "index": true }, { "name": "granted_at", "type": "timestamptz", "nullable": false, "default": "NOW()" }, { "name": "granted_by", "type": "integer", "nullable": true, "foreign_key": "user.id" } ] }
Article with Composite Index
{ "$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json", "name": "article", "columns": [ { "name": "id", "type": "big_int", "nullable": false, "primary_key": { "auto_increment": true } }, { "name": "author_id", "type": "integer", "nullable": false, "foreign_key": "user.id", "index": ["idx_author_published"] }, { "name": "title", "type": { "kind": "varchar", "length": 200 }, "nullable": false }, { "name": "slug", "type": { "kind": "varchar", "length": 200 }, "nullable": false, "unique": true }, { "name": "content", "type": "text", "nullable": false }, { "name": "status", "type": { "kind": "enum", "name": "article_status", "values": ["draft", "review", "published", "archived"] }, "nullable": false, "default": "'draft'" }, { "name": "published_at", "type": "timestamptz", "nullable": true, "index": ["idx_author_published"] }, { "name": "view_count", "type": "integer", "nullable": false, "default": 0 }, { "name": "created_at", "type": "timestamptz", "nullable": false, "default": "NOW()" } ], "constraints": [ { "type": "check", "name": "check_view_count", "expr": "view_count >= 0" } ] }
Guidelines Summary
MUST DO
- Always include
- No exceptions$schema - Always specify
- Required for every columnnullable - Validate against schema - Before saving, check IDE errors
- Index foreign key columns - Add
"index": true - Use inline constraints -
,primary_key
,unique
,index
ON the columnforeign_key
SHOULD DO
- Use enums for status/category fields - Prefer over text + CHECK
- Use integer enums for expandable sets - No migration needed for new values
- Use
overtimestamptz
- Timezone-aware is safertimestamp - Use
type for JSON data - Works across all backends (PostgreSQL, MySQL, SQLite)json
MUST NOT DO
- Never use PascalCase for reference actions - Use
not"cascade""Cascade" - Never skip schema validation - Prevents runtime errors
- Never add NOT NULL columns without default - Requires
in migrationfill_with - Never use table-level constraints - Except for CHECK expressions only
- Never manually create/edit migration files - Only
exceptionfill_with - Never manually edit exported ORM files - Use
to regeneratevespertide export - Never use
type - Usejsonb
instead (JSONB not supported in SQLite)json - Never use custom types - Use built-in types only for cross-database compatibility
- Never use array types - Use a separate join table instead (arrays not supported in SQLite)
Naming Conventions
| Item | Convention | Example |
|---|---|---|
| Tables | snake_case | |
| Columns | snake_case | |
| Indexes | | |
| Unique | | |
| Foreign Key | | |
| Check | | |
| Enums | snake_case | |
Quick Reference Card
COLUMN TYPES (simple) ──────────────────────────────────────── integer, big_int, small_int Numbers real, double_precision Floats text Strings boolean Flags date, time, timestamp, timestamptz Time interval Duration uuid UUIDs json JSON bytea Binary inet, cidr, macaddr Network xml XML COLUMN TYPES (complex) ──────────────────────────────────────── { "kind": "varchar", "length": N } { "kind": "char", "length": N } { "kind": "numeric", "precision": P, "scale": S } { "kind": "enum", "name": "...", "values": [...] } { "kind": "custom", "custom_type": "..." } REFERENCE ACTIONS (snake_case!) ──────────────────────────────────────── cascade, restrict, set_null, set_default, no_action CONSTRAINT TYPES ──────────────────────────────────────── primary_key, unique, foreign_key, check, index
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
Invalid enum in | PascalCase used | Use not |
| Missing required property | omitted | Add |
| Unknown column type | Typo in type name | Check SimpleColumnType enum |
| Foreign key validation failed | Referenced table missing | Create referenced table first |
| NOT NULL without default | Adding column to existing table | Add or use in revision |