glimr/db/gen/migrate/validation

Migration Validation

Catches schema mistakes at generation time instead of letting them become cryptic database errors at migration time. A typo in an index column or a copy-pasted duplicate column name would otherwise surface as a raw SQL error that doesn’t point back at your schema file — these checks give you a clear message with the exact table and column involved.

Values

pub fn validate_array_types(
  tables: List(schema_parser.Table),
) -> Nil

An Array(Id) would mean an auto-incrementing primary key that’s also a list — which no database supports. Array(Foreign("users")) would imply FK constraints on each element, but Postgres arrays can’t enforce that. Both would generate invalid SQL, so we catch them here with a message that explains why instead of letting the database reject the migration cryptically.

pub fn validate_enum_variants(
  tables: List(schema_parser.Table),
) -> Nil

Enum columns need at least one variant, can’t have empty variant strings, and can’t have duplicate variants. Without these checks, the generated Gleam custom type would be invalid or the database CHECK/CREATE TYPE would fail.

pub fn validate_indexes(tables: List(schema_parser.Table)) -> Nil

Catches index mistakes before they become cryptic SQL errors. Indexing a column that doesn’t exist would fail at migration time with a database error that doesn’t point at your schema file. Duplicate indexes waste disk space and slow down writes for no benefit. Both are caught here with clear error messages pointing at the exact table and columns involved.

pub fn validate_no_duplicate_columns(
  tables: List(schema_parser.Table),
) -> Nil

A duplicate column name would generate invalid SQL (CREATE TABLE with two columns of the same name), but the database error message won’t tell you which schema file caused it. This catches the mistake early and names the table and the duplicated columns so you can go fix it immediately.

Search Document