Skip to content

Importers

Manech Dubreil edited this page Oct 16, 2026 · 4 revisions

Importers

An importer turns a source ORM's schema text into a pivot::Schema. Every importer implements the same trait, defined in crates/core/src/importer/mod.rs:

pub trait Importer {
    fn import(&self, input: &str) -> Result<Schema, ImportError>;
}

pub enum ImportError {
    Parse(String),   // input could not be parsed at all
    Schema(String),  // parsed, but semantically invalid (e.g. unknown type reference)
}

Available importers

ORM Page Module File extension
Prisma Prisma Importer crates/core/src/importer/prisma/ (PrismaImporter) .prisma

Each importer is registered in crates/core/src/registry.rs alongside its file extension so the CLI can auto-detect it.

Adding a new importer

Following the Prisma importer:

  1. Create a new module under crates/core/src/importer/<orm_name>/ and implement the Importer trait on a zero-sized (or config-holding) struct, mirroring PrismaImporter.
  2. Keep any parser-specific intermediate representation (your equivalent of ast.rs) private to your module (pub(super)), and only ever construct/return pivot::Schema at the boundary.
  3. Never mutate pivot types from within the importer. If the source ORM has a feature with no IR equivalent, add it to OrmMetadata.unknown_features rather than proposing a pivot change from inside the importer — pivot changes are cross-cutting and must keep every importer/exporter consistent.
  4. Register the ORM in crates/core/src/registry.rs's ORMS slice with its file extension(s) and a make_importer factory — see CLI for the exact shape.
  5. Add tests following the existing crates/core/src/importer/prisma/tests.rs style: focused unit tests per feature, plus one comprehensive test parsing a realistic multi-table fixture (see test.prisma at the repo root and the parse_full_test_schema test) and asserting a full JSON round-trip. See Testing for how to run the suite and the CI quality gates every PR must pass.

Exporters

crates/core/src/exporter/mod.rs defines the mirror-image trait, with no implementations yet:

pub trait Exporter {
    fn export(&self, schema: &Schema) -> Result<String, ExportError>;
}

pub enum ExportError {
    Unsupported(String), // the schema contains a construct with no target-ORM equivalent
    Render(String),      // serialization failed for an internal reason
}

When the first exporter is implemented, it will be registered the same way as an importer — via make_exporter in the relevant OrmDescriptor in crates/core/src/registry.rs.

Clone this wiki locally