Skip to main content

Synopsis

Generate, validate, or apply database migrations from schema files.

Description

The migrate command:
  1. Verifies Schema Vault integrity - Checks all version hashes
  2. Checks paranoid mode - Ensures schema changes are allowed
  3. Loads and merges schemas - Combines all .cham files from configured paths
  4. Detects changes - Compares merged schema with current vault version
  5. Generates migration SQL - Creates DDL statements
  6. Registers new version - Creates immutable snapshot in vault (if --apply)
  7. Applies migration - Executes SQL against database (if --apply)
  8. Updates state - Records migration in manifest and journal
By default, runs in check mode (shows pending migrations without applying).

Flags

boolean
default:"true"
Check for pending migrations without applying (default behavior)
boolean
default:"false"
Preview migration SQL without applying to database
Shows:
  • Schema changes summary
  • Generated SQL
  • Does NOT register version or apply migration
boolean
default:"false"
Apply migration to database
  • Registers new schema version in vault
  • Executes migration SQL
  • Updates state and journal
  • Creates backup (if enabled in config)

Environment Variables

string
required
PostgreSQL connection string
string
Used as author name for schema versions. Defaults to “unknown” if not set.

Examples

Check for Pending Migrations

Output (no changes):
Output (changes detected):

Preview Migration SQL

Output:

Apply Migration

Output:

Before Migration

Schema Files

schemas/users.cham:

Vault State

Output:

After Migration

Modified Schema

schemas/users.cham:

Run Migration

Updated Vault State

Output:

Paranoid Mode Behavior

Readonly Mode (Default)

Error:

Standard Mode

Integrity Verification

Integrity Check Passed

Integrity Violation Detected

Error Handling

Connection Failure

Schema Validation Error

Migration Execution Error

Migration Retry

If a migration fails, ChameleonDB tracks it:

Configuration

Migration behavior is controlled by .chameleon.yml:

See Also