Skip to main content

Synopsis

Introspect an existing database and generate a ChameleonDB schema.

Description

The introspect command:
  1. Connects to existing database - Uses provided connection string
  2. Scans all tables - Detects user tables, columns, types
  3. Generates schema - Creates ChameleonDB .cham schema file
  4. Respects paranoid mode - Blocked in readonly mode
  5. Handles overwrites safely - Prompts before replacing existing schemas
Supported databases:
  • ✅ PostgreSQL
  • 🚧 MySQL (coming soon)
  • 🚧 SQLite (coming soon)

Arguments

string
required
Database connection string or environment variable referenceFormats:
  • Direct URL: postgresql://user:pass@localhost/db
  • Env variable: $DATABASE_URL
  • Env variable: ${DATABASE_URL}
  • Env variable: env:DATABASE_URL

Flags

string
default:"schema.cham"
Output file path (auto-prefixed with schemas/)
Result: schemas/myschema.cham
boolean
default:"false"
Force overwrite without confirmation
Warning: Use with caution. Overwrites existing schema without backup.

Examples

Basic Introspection

Output:

Custom Output File

Output:

Using Environment Variable

Or:

Force Overwrite

Output:

Before Introspection

Existing Database

PostgreSQL tables:

After Introspection

Generated Schema

schemas/schema.cham:

Manual Adjustments

You may need to add relationships manually:

Paranoid Mode Behavior

Readonly Mode (Default)

Error:

Standard Mode

Overwrite Protection

Default Schema Detected

If schemas/schema.cham contains the default schema from chameleon init:
Output:

Modified Schema Detected

If schemas/schema.cham has custom entities:
Output:

Using Different Output File

Connection String Formats

PostgreSQL

Environment Variable References

Error Handling

Connection Failed

Error:

Database Not Detected

Error:

No Tables Found

Output:
Generated schema:

Permission Denied

Error:

Type Mapping

PostgreSQL to ChameleonDB

Limitations

Not Detected

  • Relationships - Foreign keys detected but not converted to relations
  • Indexes - Not included in schema
  • Triggers - Not supported
  • Views - Only tables are introspected
  • Constraints - Only PRIMARY and UNIQUE detected

Manual Post-Processing

After introspection, you may need to:
  1. Add relationships:
  2. Add indexes:
  3. Refine types:

Best Practices

1. Introspect to New File

Preserves existing schema for comparison.

2. Review Before Committing

3. Use in CI/CD

See Also