Table.Columns/Constraints/Indexes/Relationships are Go maps, and every writer, reader, diff, inspector, and merge code path that iterated them directly was subject to Go's randomized map order, so identical input could produce different output (or a different in-report violation/diff order) on every run. Most visibly this showed up as bun/gorm `unique:` struct tags changing order across consecutive `make models` runs with no source change. Fixed by sorting map iteration (by Sequence then Name, or alphabetically for string-keyed maps) everywhere the order affects generated output or first-match tie-break logic, across the bun, gorm, sqlite, dbml, drawdb, pgsql, prisma, graphql, typeorm, drizzle, and dctx writers; the dctx, prisma, and typeorm readers; the shared models.GetPrimaryKey/ GetForeignKeys helpers; pkg/diff, pkg/inspector, and pkg/merge; and the TUI column/relationship pickers in pkg/ui.
Prisma Reader
Reads Prisma schema files and extracts database schema information.
Overview
The Prisma Reader parses .prisma schema files that define database models using Prisma's schema language and converts them into RelSpec's internal database model representation.
Features
- Parses Prisma schema syntax
- Extracts models, fields, and relationships
- Supports Prisma attributes and directives
- Handles enums and composite types
Usage
Basic Example
package main
import (
"fmt"
"git.warky.dev/wdevs/relspecgo/pkg/readers"
"git.warky.dev/wdevs/relspecgo/pkg/readers/prisma"
)
func main() {
options := &readers.ReaderOptions{
FilePath: "/path/to/schema.prisma",
}
reader := prisma.NewReader(options)
db, err := reader.ReadDatabase()
if err != nil {
panic(err)
}
fmt.Printf("Found %d schemas\n", len(db.Schemas))
}
CLI Example
# Read Prisma schema and convert to JSON
relspec --input prisma --in-file schema.prisma --output json --out-file schema.json
# Convert Prisma to GORM models
relspec --input prisma --in-file schema.prisma --output gorm --out-file models.go
Example Prisma Schema
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int @id @default(autoincrement())
username String @unique @db.VarChar(50)
email String @db.VarChar(100)
createdAt DateTime @default(now()) @map("created_at")
posts Post[]
@@map("users")
}
model Post {
id Int @id @default(autoincrement())
userId Int @map("user_id")
title String @db.VarChar(200)
content String @db.Text
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("posts")
}
Supported Prisma Attributes
@id- Primary key@unique- Unique constraint@default- Default value@map- Column name mapping@@map- Table name mapping@relation- Relationship definition@db.*- Database-specific type annotations
Notes
- Extracts datasource provider information
- Supports
@@mapfor custom table names - Handles Prisma-specific types and converts them to standard SQL types