Exporters
An exporter turns a validated schema into target-specific output. Each one is a pure function: a TitanSchema in, files (and warnings) out. Validate first, then export — see Diagnostics.
Most exporters return the shared ExportResult shape from @titanbase/core:
interface ExportResult {
files: { path: string; content: string }[];
warnings: { code: string; message: string; path?: string }[];
}
The PostgreSQL exporter is the one exception today: it returns { sql: string; warnings: string[] }.
Titan JSON#
Status: Available- Output file:
<project>.titan.json - Supports: the complete schema — the canonical, portable source of truth.
- How it's produced:
JSON.stringify(schema, null, 2)(2-space JSON). On load, the schema is normalized (strings trimmed;tables,enums, andrelationssorted by name). - Warnings: none — this is a faithful serialization of your schema.
This is the file you keep in version control and reopen in the editor.
PostgreSQL SQL#
Status: Available@titanbase/export-postgres — exportPostgres(schema)
- Output file:
<project>.sql - Returns:
{ sql, warnings }
Supports:
CREATE SCHEMAfor any table that sets aschemanamespaceCREATE TYPE ... AS ENUMfor enumsCREATE TABLEwith columns,NOT NULL,UNIQUE, andDEFAULT- Primary keys as a named
CONSTRAINT ... PRIMARY KEY(single or composite) - Foreign keys via
ALTER TABLE ... ADD CONSTRAINT, withON DELETE/ON UPDATE - Indexes, including
USING <method>, partialWHERE, andUNIQUE COMMENT ONfor tables, columns, indexes, constraints, and types (fromdescription)- Safe identifier quoting and deterministic output
Known limitations / warnings:
- An unknown column type falls back to
textwith a warning. - An index referencing a missing column is skipped with a warning.
- An unsupported index method is emitted without
USINGand warned. - A non-
postgres/genericdialect is warned (types may not be supported).
CREATE TYPE "post_status" AS ENUM ('draft', 'published', 'archived');
CREATE TABLE "users" (
"id" uuid NOT NULL DEFAULT gen_random_uuid(),
"email" text NOT NULL UNIQUE,
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);
ALTER TABLE "posts" ADD CONSTRAINT "posts_author_id_fkey"
FOREIGN KEY ("author_id") REFERENCES "users" ("id") ON DELETE CASCADE;
Mermaid ERD#
Status: Available@titanbase/export-mermaid — exportMermaid(schema, options?)
- Output file:
schema.mmd - Returns:
ExportResult
Supports:
- An
erDiagramwith one entity per table - Columns with their type label and
PK/FK/UKmarkers (toggle withincludeColumnKeys) - Relations with cardinality connectors and a label
Known limitations / warnings:
- Multi-column indexes are not represented (warned).
- Partial indexes and non-
btreemethods are not represented (warned). - Identifier collisions are auto-renamed (warned).
- A relation referencing a missing table is skipped; a missing column is warned but the table-level relation is still drawn.
erDiagram
users {
uuid id PK
text email UK
}
posts {
uuid id PK
uuid author_id FK
text title
}
posts }o--|| users : "posts_author_id_fkey"
Prisma schema#
Status: Available@titanbase/export-prisma — exportPrisma(schema, options?)
- Output file:
schema.prisma - Returns:
ExportResult
Supports:
generatoranddatasourceblocks (provider defaults topostgresql, URL env defaults toDATABASE_URL)modelblocks with scalar fields,@id/@@id,@unique, and@defaultenumblocks, with@mapfor values that need it@@index/@@uniquewhere safe@map/@@mapfor names that aren't valid Prisma identifiers- Relation fields for
many-to-oneandone-to-onerelations, withonDelete/onUpdate
Known limitations / warnings:
many-to-manyandone-to-manyrelations, or relations whose target isn't a primary/unique key, keep their scalar columns and emit an "ambiguous relation" warning instead of generating a relation field.- Partial index predicates and non-
btreemethods are omitted (warned). - Unsupported column types fall back to
String(warned); unsupported defaults are omitted (warned). - Table
schemanamespaces require Prisma multi-schema config and are omitted (warned).
model User {
id String @id @default(uuid()) @db.Uuid
email String @unique
posts Post[] @relation("posts_author_id_fkey")
}
Drizzle (PostgreSQL) schema#
Status: Available@titanbase/export-drizzle — exportDrizzle(schema, options?)
- Output file:
schema.ts(configurable viaschemaFilePath) - Returns:
ExportResult
Supports:
pgTableandpgEnumdeclarations- Column builders (
uuid,text,integer,bigint,boolean,timestamp,date,numeric,jsonb,varchar) .primaryKey(),.notNull(),.unique(), and.default*()helpers where safe- Single and composite primary keys, indexes (
index/uniqueIndex), and foreign keys - Tables ordered by dependency so references resolve
Known limitations / warnings:
- Self-referencing foreign keys are omitted (warned); cyclic dependencies are reported so you can move a foreign key into a migration.
- Floating-point types are approximated with
numeric()(warned). - Partial index predicates and non-
btreemethods are omitted (warned). - Unsupported types fall back to
text()(warned); unsupported defaults are omitted (warned). - Table
schemanamespaces requirepgSchemaand are omitted (warned).
import { pgTable, uuid, text } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
id: uuid("id").primaryKey().notNull().defaultRandom(),
email: text("email").notNull().unique(),
}
);
Warnings#
Every exporter returns warnings alongside its output rather than failing. A warning means the target can't fully represent something and the exporter chose a safe fallback — review them before applying the result. Exporter warnings are target-specific and complement the general schema diagnostics.
Planned exporters#
Status: PlannedThese targets are on the roadmap and not available yet:
- DBML
- MySQL
- SQLite
- Neon / Supabase presets
Want a target that isn't here yet? See the Plugin API and Contributing.