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
| Parameter | Short | Description | Default |
|---|---|---|---|
<database-url> | - | Database connection string (required) | - |
--output | -o | Output file path | schema.cham |
--force | -f | Bypass overwrite safety checks | false |
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:
Basic Introspection Workflow
Ensure Proper Mode
Introspection requires See Mode Management for details.
standard mode or higher (blocked in readonly):Mode Restrictions
Introspection behavior depends on your current integrity mode:| Mode | Introspect Behavior |
|---|---|
readonly | ❌ Blocked |
standard | ✅ Allowed |
privileged | ✅ Allowed |
emergency | ✅ Allowed |
Upgrading from readonly
Since mode upgrades require password authentication:Mode upgrade requires password (e.g.,
readonly → standard)Mode downgrade does NOT require password (e.g., standard → readonly)Output File Safety Checks
Without--force, introspection applies safety protections:
1. Directory Check
Validates that the output path is not a directory:2. Template Detection
Detects default template schemas created bychameleon init:
schema.cham is an unmodified template:
3. Modified Schema Detection
Detects working schemas and prompts for safety:4. Force Overwrite
Bypass all safety checks:Complete Examples
Baseline Introspection (Railway-style)
Introspect a Railway PostgreSQL instance:Explicit Environment Resolver
Use explicitenv: syntax:
Overwrite Existing Schema Intentionally
Force overwrite without prompts:Introspect Production Database
Post-Introspection Workflow
1. Validate Generated Schema
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 is read-only
Introspection is read-only
Introspection only reads database metadata. It never modifies your database.
Review generated relations
Review generated relations
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)
Naming conventions
Naming conventions
Introspection uses database table/column names directly. You may want to:
- Convert
snake_casetoPascalCasefor entities - Use singular names (e.g.,
Userinstead ofusers)
Follow up with validation
Follow up with validation
Always validate after introspection:
Use version control
Use version control
Track generated schemas in Git to review changes:
Best Practices
-
Use separate files for introspection
Compare with your working schema before merging.
-
Version introspected schemas
-
Always validate after introspection
-
Review before applying