prisma-to-ecto
v0.0.2
Published
Convert Prisma schema to Ecto schema with migrations
Maintainers
Readme
prisma-to-ecto
Convert Prisma schemas into Elixir Ecto schemas and migrations.
prisma-to-ecto is a CLI tool that reads a Prisma schema.prisma file and generates:
- Ecto schemas (
.ex) - Ecto migrations (
.exs) - Enum modules
- Join tables for implicit many-to-many relations
- View schema stubs
It helps teams migrating from Prisma → Elixir / Phoenix / Ecto or maintaining a Prisma-first schema workflow.
Installation
Global Installation (Recommended)
npm install -g prisma-to-ectoRun the CLI:
prisma-to-ecto convertLocal Installation
Install inside your project:
npm install --save-dev prisma-to-ectoRun using npx:
npx prisma-to-ecto convertProject Structure
Your project only needs the Prisma schema.
Example:
my-project/
├── prisma/
│ └── schema.prisma
├── lib/
│ └── my_app/
├── priv/
│ └── repo/
│ └── migrations/
└── package.jsonOnly prisma/schema.prisma is required.
Place Your Prisma Schema
Create the Prisma directory if it doesn't exist:
mkdir -p prismaPlace your schema at:
prisma/schema.prismaRunning the Converter
Default Conversion
npx prisma-to-ecto convertDefault output:
Schema: ./prisma/schema.prisma
Schemas → ./prisma-to-ecto/schemas
Migrations → ./prisma-to-ecto/migrationsCustom Output Directories
npx prisma-to-ecto convert ./prisma/schema.prisma \
--schema-out ./lib/my_app \
--migration-out ./priv/repo/migrationsGenerate Schemas Only
npx prisma-to-ecto convert --no-migrationsGenerate Migrations Only
npx prisma-to-ecto convert --no-schemasCLI Help
npx prisma-to-ecto --helpExample Output
prisma-to-ecto
Schema: ./prisma/schema.prisma
Schemas → ./lib/my_app
Migrations → ./priv/repo/migrations
Parsed 20 model(s), 8 enum(s)
Generating Ecto schemas...
✓ user.ex
✓ task.ex
✓ project_stats.ex
... (28 total files)
Generating migrations...
✓ ..._create_users.exs
✓ ..._create_tasks.exs
✓ ..._create_label_task.exs
... (23 total files)
✓ Done!Generated Files
Example structure:
lib/my_app/
├── user.ex
├── task.ex
├── notification_preference.ex
├── audit_log.ex
└── user_role.ex
priv/repo/migrations/
├── ..._create_users.exs
├── ..._create_tasks.exs
├── ..._create_label_task.exs
└── ..._create_view_project_statses.exsSupported Prisma Features
The converter supports advanced Prisma schema features.
| Feature | Example |
| ------------------------- | -------------------------------- |
| UUID primary keys | @id @default(uuid()) |
| Database schemas | @@schema("auth") |
| Referential actions | Cascade, SetNull, Restrict |
| Named relations | Task.assignee, Task.reporter |
| Self-referential models | Task.subtasks |
| Database annotations | @db.VarChar(320) |
| Full-text indexes | @@fulltext |
| Enum mapping | @map |
| Composite primary keys | @@id([userId, channel]) |
| Custom table names | @@map |
| Views | view ProjectStats |
| BigInt | Attachment.sizeBytes |
| Decimal | Invoice.amountCents |
| JSON fields | Json |
| Implicit many-to-many | Task ↔ Label |
| Sensitive field detection | password / secret / token |
Manual Review After Conversion
The generator may add TODO comments for items requiring manual review.
| Item | Location | Action |
| -------------- | -------------------- | --------------------------------------- |
| Foreign keys | User.assignedTasks | Set correct foreign_key: |
| Database views | View migration | Write SQL query |
| Enums | Migrations | Create Postgres enum type or use string |
Example package.json Script
Add a shortcut command:
{
"scripts": {
"convert": "prisma-to-ecto convert"
}
}Run with:
npm run convertUsing With Phoenix / Ecto
After generating migrations:
mix ecto.migrateLicense
MIT
