Add Prisma 7 flag support
This commit is contained in:
@@ -70,6 +70,7 @@ func (r *Reader) ReadTable() (*models.Table, error) {
|
||||
// parsePrisma parses Prisma schema content and returns a Database model
|
||||
func (r *Reader) parsePrisma(content string) (*models.Database, error) {
|
||||
db := models.InitDatabase("database")
|
||||
db.SourceFormat = "prisma"
|
||||
|
||||
if r.options.Metadata != nil {
|
||||
if name, ok := r.options.Metadata["name"].(string); ok {
|
||||
@@ -139,7 +140,7 @@ func (r *Reader) parsePrisma(content string) (*models.Database, error) {
|
||||
case "datasource":
|
||||
r.parseDatasource(blockContent, db)
|
||||
case "generator":
|
||||
// We don't need to do anything with generator blocks
|
||||
r.parseGenerator(blockContent, db)
|
||||
case "model":
|
||||
if currentTable != nil {
|
||||
r.parseModelFields(blockContent, currentTable)
|
||||
@@ -173,10 +174,34 @@ func (r *Reader) parsePrisma(content string) (*models.Database, error) {
|
||||
// Second pass: resolve relationships
|
||||
r.resolveRelationships(schema)
|
||||
|
||||
if db.SourceFormat == "prisma" && r.options != nil && r.options.Prisma7 {
|
||||
db.SourceFormat = "prisma7"
|
||||
}
|
||||
|
||||
db.Schemas = append(db.Schemas, schema)
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func (r *Reader) parseGenerator(lines []string, db *models.Database) {
|
||||
providerRegex := regexp.MustCompile(`provider\s*=\s*"([^"]+)"`)
|
||||
|
||||
for _, line := range lines {
|
||||
if matches := providerRegex.FindStringSubmatch(line); matches != nil {
|
||||
switch matches[1] {
|
||||
case "prisma-client":
|
||||
db.SourceFormat = "prisma7"
|
||||
default:
|
||||
db.SourceFormat = "prisma"
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if r.options != nil && r.options.Prisma7 {
|
||||
db.SourceFormat = "prisma7"
|
||||
}
|
||||
}
|
||||
|
||||
// parseDatasource extracts database type from datasource block
|
||||
func (r *Reader) parseDatasource(lines []string, db *models.Database) {
|
||||
providerRegex := regexp.MustCompile(`provider\s*=\s*"?(\w+)"?`)
|
||||
|
||||
Reference in New Issue
Block a user