Skip to main content
The chameleon introspect command inspects an existing database schema and generates a ChameleonDB schema file (.cham). This is essential for:
  • Bootstrapping from legacy databases
  • Validating table discovery
  • Generating baseline schemas for migration workflows
Currently, introspection only supports PostgreSQL. Support for MySQL and other databases is planned for v1.2+.

Command Syntax

Parameters

Connection String Formats

ChameleonDB supports multiple connection string formats for flexibility:

1. Direct URL

Provide the full connection string directly:

2. Shell-style Environment Variable ($VAR)

Reference an environment variable using shell syntax:

3. Braced Environment Variable (${VAR})

Use braced syntax for clarity:

4. Explicit Environment Reference (env:VAR)

Use explicit env: prefix:
If the referenced environment variable is missing or empty, the command will fail with an explicit error message.

Basic Introspection Workflow

1

Set Your Connection String

Export your database URL as an environment variable:
2

Ensure Proper Mode

Introspection requires standard mode or higher (blocked in readonly):
See Mode Management for details.
3

Run Introspection

Generate the schema file:
Output:
4

Review Generated Schema

Open the generated file and review:
Example output:
5

Validate and Customize

Validate the schema and make manual adjustments:
Common customizations:
  • Rename entities to match your conventions
  • Add missing relations
  • Adjust field types
  • Add default values

Mode Restrictions

Introspection behavior depends on your current integrity mode:

Upgrading from readonly

Since mode upgrades require password authentication:
Mode upgrade requires password (e.g., readonlystandard)Mode downgrade does NOT require password (e.g., standardreadonly)

Output File Safety Checks

Without --force, introspection applies safety protections:

1. Directory Check

Validates that the output path is not a directory:
Output:

2. Template Detection

Detects default template schemas created by chameleon init:
If schema.cham is an unmodified template:

3. Modified Schema Detection

Detects working schemas and prompts for safety:
Output:

4. Force Overwrite

Bypass all safety checks:
Use --force carefully — it will overwrite existing files without confirmation.

Complete Examples

Baseline Introspection (Railway-style)

Introspect a Railway PostgreSQL instance:

Explicit Environment Resolver

Use explicit env: syntax:

Overwrite Existing Schema Intentionally

Force overwrite without prompts:

Introspect Production Database

Post-Introspection Workflow

1. Validate Generated Schema

Expected output:

2. Review Relations

Introspection discovers foreign keys but may need manual review:

3. Customize Naming

Rename entities to match your conventions:

4. Apply Migration

Once satisfied, apply to initialize vault:

Common Issues

”readonly mode: introspection blocked”

Solution: Upgrade mode:

“DATABASE_URL environment variable not set”

Solution: Export the variable:

“output path is a directory”

Solution: Specify a file path:

“connection refused”

Solution: Verify database is running and accessible:

Operational Notes

Introspection only reads database metadata. It never modifies your database.
Foreign keys are auto-discovered, but you should manually verify:
  • Relation names make sense
  • Reverse relations are added where needed
  • Cardinality is correct (one-to-many vs many-to-many)
Introspection uses database table/column names directly. You may want to:
  • Convert snake_case to PascalCase for entities
  • Use singular names (e.g., User instead of users)
Always validate after introspection:
Track generated schemas in Git to review changes:

Best Practices

  1. Use separate files for introspection
    Compare with your working schema before merging.
  2. Version introspected schemas
  3. Always validate after introspection
  4. Review before applying

Next Steps

Migration Workflow

Apply introspected schema to database

Schema Language

Learn schema syntax and features

Mode Management

Understand integrity modes

Debugging

Troubleshoot introspection issues