Skip to content

Validation

Arael Espinosa edited this page Apr 6, 2026 · 2 revisions

Validation

The validate command (and the pre-execution check in run) connects to the source database to verify that the configuration is consistent with the actual schema before any data is touched.

Running Validation

dotnet DbMigrator.dll validate --config config.yaml

Exit code 0 = valid, exit code 1 = one or more errors.

Add --strict to also fail on warnings:

dotnet DbMigrator.dll validate --config config.yaml --strict

What Is Checked

Config-Level Checks (no DB connection required)

Check Severity
Required fields are present (host, database) Error
port is in range 1–65535 Error
ssl_mode is one of: Disable, Allow, Prefer, Require, VerifyCA, VerifyFull Error
Source and target point to the same database (same host + port + database) Error
Table name contains characters other than letters, digits, and underscores Error
Column name contains characters other than letters, digits, and underscores Error
Each sanitization entry has a recognized strategy Error
faker strategy is missing the faker method field Error
template strategy is missing the value field Error
parallel_jobs is less than 1 Error
${ENV_VAR} references resolve to a non-empty value Error

Why identifier validation matters: Table and column names are injected directly into SQL UPDATE statements. Restricting them to ^[a-zA-Z_][a-zA-Z0-9_]*$ prevents SQL injection through the config file.

Schema-Level Checks (connects to source DB)

Check Severity
Table does not exist in source Error
Column does not exist in table Error
null_value strategy on a NOT NULL column Error
static with value: null on a NOT NULL column Error
Faker method name is not recognized Error
Faker method returns text but column type is numeric Warning
Sanitizing a primary key column Warning
Target table has zero rows Warning

Interpreting Output

The CLI prints a summary table per table. Errors are shown in red, warnings in yellow.

✓  users           — 3 columns OK
✗  payments        — column "cvv" not found
⚠  sessions        — table has 0 rows

Skipping Validation

You can skip schema validation (e.g., when source DB is not accessible from CI) with:

dotnet DbMigrator.dll run --config config.yaml --skip-validation

Config-level checks (field presence, env vars, strategy names) are always run and cannot be skipped.

Clone this wiki locally