Schema Validation
Schema validation runs automatically on push and migrate — call it manually for early startup checks
Schema validation checks your models for structural errors — missing IDs, broken foreign keys, invalid referential actions, database-specific constraints — before anything touches the database. It runs automatically on viborm push and viborm migrate; you only call it yourself if you want errors surfaced at application startup.
Manual Validation
import { validateSchema, validateSchemaOrThrow } from "viborm";
import * as schema from "./schema";
// Throws with all error messages if the schema is invalid (good for startup)
validateSchemaOrThrow(schema);
// Or inspect the result yourself
const result = validateSchema(schema);
if (!result.valid) {
for (const error of result.errors) {
console.log(`[${error.code}] ${error.message}`);
}
}
for (const warning of result.warnings) {
console.log(`[${warning.code}] Warning: ${warning.message}`);
}
validateSchema(models) returns { valid, errors, warnings }, where each entry has a code, a severity ("error" | "warning"), and a human-readable message. validateSchemaOrThrow(models) throws an Error listing every failed check.
Example Errors
[M001] 'user' must have an ID field (or use .id() for compound key)
[F006] ID 'id' in 'user' cannot be nullable
[F004] Default value for 'age' in 'user' doesn't match type