Generate Prax schemas from existing databases with the prax db pull command.
Schema introspection analyzes your existing database and generates a Prax schema file. This is useful for migrating existing projects or keeping your schema in sync with database changes.
Types, constraints, defaults
Foreign keys, references
Performance optimizations
The simplest way to generate a schema from your database.
Include or exclude specific tables using glob patterns.
Optionally include views and materialized views in the generated schema.
Export the schema in different formats for various use cases.
MongoDB is schemaless, so Prax infers the schema by sampling documents.
Here's what an introspected schema looks like:
Use the introspection API directly in your Rust code.
Prax analyzes document samples to infer types, including arrays and embedded documents.
How database types are mapped to Prax types:
| Option | Description | Default |
|---|---|---|
--output, -o |
Output file path | prax/schema.prax |
--force, -f |
Overwrite without prompting | false |
--schema, -s |
Database schema to introspect | public/dbo |
--tables |
Glob pattern for tables | * (all) |
--exclude |
Glob pattern to exclude | none |
--include-views |
Include views | false |
--include-materialized-views |
Include materialized views | false |
--comments |
Include column comments | false |
--format |
Output format (prax, json, sql) | prax |
--print |
Print to stdout | false |
--sample-size |
MongoDB sample size | 100 |
Always review the generated schema. Introspection infers relations from foreign keys, but you may want to add or adjust relation names for clarity.
Commit your schema file to version control. Compare diffs after re-introspecting to catch unexpected database changes.
For MongoDB, use a larger sample size if your documents vary significantly. This improves type inference accuracy but takes longer.
Use --exclude to skip migration tables, Prisma internals (_prisma*),
and other non-application tables.