Skip to main content

Synopsis

Validate a schema file for syntax and semantic errors.

Description

The validate command checks schema files for:
  • Syntax errors - Malformed schema syntax
  • Type errors - Invalid or unknown types
  • Reference errors - Missing entities or fields
  • Constraint errors - Invalid primary keys, unique constraints
  • Circular dependencies - Detect entity reference cycles
If no file is specified, looks for schema.cham in the current directory.

Arguments

string
Path to schema file to validateDefault: schema.cham in current directory

Flags

boolean
default:"false"
Show detailed validation checks passed

Examples

Validate Default Schema

Output (valid):
Output (with —verbose):

Validate Specific File

Output:

Validation Errors

Syntax Error

schemas/invalid.cham:
Output:

Missing Primary Key

schemas/no-pk.cham:
Output:

Invalid Reference

schemas/bad-ref.cham:
Output:

Circular Dependency

schemas/circular.cham:
Output:

Valid Schema Example

schemas/blog.cham:
Output:

File Not Found

Output:

Validation Checks

The validator performs these checks:

1. Syntax Validation

  • Correct entity declarations
  • Valid field syntax
  • Proper use of keywords (primary, unique, default)

2. Type Checking

  • All types are recognized (uuid, string, int, bool, timestamp, etc.)
  • Array types are properly declared

3. Semantic Validation

  • Each entity has a primary key
  • Referenced entities exist
  • Foreign key types match target primary keys
  • No duplicate field names within an entity

4. Constraint Validation

  • Unique constraints are properly defined
  • Default values match field types
  • Indexes reference existing fields

5. Relationship Validation

  • Foreign key relationships are valid
  • No unresolvable circular dependencies

Exit Codes

  • 0 - Schema is valid
  • 1 - Validation failed or file not found

Integration with Migrate

Validation is automatically performed during migration:
If validation fails, migration is aborted:

Best Practices

1. Validate Before Committing

2. Validate All Schemas

If you have multiple schema files:

3. CI/CD Integration

Troubleshooting

Validation Passes but Migration Fails

The validate command only checks syntax and semantics, not database compatibility. Use migrate --dry-run to check generated SQL:

Multiple Schema Files

To validate across multiple files, use migrate --check:
This validates the merged schema from all files in schema.paths.

See Also