Skip to content

Conversation

@QUBITABHAY
Copy link

Overview

Adds support for importing Prisma ORM schema files into DrawDB with automatic SQL export to the detected database provider.

Changes

  • Added Prisma schema import option in File > Import from menu (marked as Beta)
  • Implemented fromPrisma() parser in src/utils/importFrom/prisma.js
  • Parse model blocks → tables with fields
  • Parse enum blocks → enums
  • Parse @relation() → relationships with cardinality inference
  • Parse field attributes: @id, @@id([...]), @unique, @default(), autoincrement()
  • Detect datasource provider and auto-set diagram database
  • Auto-arrange imported tables on canvas
  • Reject the MongoDB provider with a clear error message

Supported Prisma Features

Models & Fields

  • Model declarations → tables
  • Field types, nullability (?), lists ([])
  • Primary keys: @id and composite @@id([field1, field2])
  • Unique constraints: @unique
  • Default values: @default(value) including autoincrement()

Relationships

  • @relation(fields: [...], references: [...])
  • Cardinality inference (one-to-many for list types, many-to-one otherwise)
  • Named relations via name: \"relationName\"

Enums

  • Full enum support

Datasource Detection

Automatically detects and maps the provider to the diagram database:

  • `postgresql` / `postgres` → PostgreSQL
  • `mysql` → MySQL
  • `mariadb` → MariaDB
  • `sqlite` → SQLite
  • `sqlserver` → SQL Server
  • `cockroachdb` → PostgreSQL
  • `mongodb` → rejected (not SQL)

Usage

  1. Open DrawDB editor
  2. File → Import from → Prisma schema (Beta)
  3. Upload your `.prisma` file
  4. Tables, relationships, and enums are imported
  5. Export to SQL using the detected database provider

Limitations (Beta)

  • Does not parse composite types or views
  • Limited support for advanced Prisma features (e.g., named indexes from @@unique([...]), @@index)
  • Does not parse @map / @@map for custom column/table names
  • No onDelete / onUpdate cascade parsing yet

Testing

  • ESLint passes on all changed files
  • Import flow integrated with the existing modal system
  • Error handling for malformed schemas
  • Database provider detection is working

Files Changed

  • `src/data/constants.js` — Added IMPORT_FROM.PRISMA
  • `src/components/EditorHeader/ControlPanel.jsx` — Added menu option
  • `src/components/EditorHeader/Modal/ImportDiagram.jsx` — Prisma file handling
  • `src/components/EditorHeader/Modal/Modal.jsx` — Database auto-setting
  • `src/utils/importFrom/prisma.js` — New parser implementation

Closes issue #681

- Add IMPORT_FROM.PRISMA constant - Implement fromPrisma() parser for Prisma schema files - Parse models -> tables with fields, enums, and relationships - Detect datasource provider and auto-set diagram database (PostgreSQL, MySQL, SQLite, MariaDB, SQL Server) - Parse @id, @@id([...]), @unique, @default(), autoincrement - Parse @relation() for FK relationships with cardinality inference - Add "Prisma schema (Beta)" option in File > Import from menu - Support .prisma file upload in import modal - Auto-arrange imported tables on canvas - Reject MongoDB provider with clear error message Allows users to import Prisma ORM schemas and export to respective SQL databases.
@vercel
Copy link

vercel bot commented Nov 8, 2025

@QUBITABHAY is attempting to deploy a commit to the dottle's projects Team on Vercel.

A member of the Team first needs to authorize it.

@QUBITABHAY
Copy link
Author

@1ilit, please review it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant