Bugs Fixed
1. pkg/models/models.go:184 - Fixed typo in ForeignKeyConstraint constant from "foreign_Key" to "foreign_key" 2. pkg/readers/drawdb/reader.go:62-68 - Fixed ReadSchema() to properly detect schema name from tables instead of hardcoding "default" 3. pkg/writers/dbml/writer.go:128 - Changed primary key attribute from "primary key" to DBML standard "pk" 4. pkg/writers/dbml/writer.go:208-221 - Fixed foreign key reference format to use "table.column" syntax for single columns instead of "table.(column)" Test Results All reader and writer tests are now passing: Readers: - DBML: 74.4% coverage (2 tests skipped due to missing parser features for Ref statements) - DCTX: 77.6% coverage - DrawDB: 83.6% coverage - JSON: 82.1% coverage - YAML: 82.1% coverage Writers: - Bun: 68.5% coverage - DBML: 91.5% coverage - DCTX: 100.0% coverage - DrawDB: 83.8% coverage - GORM: 69.2% coverage - JSON: 82.4% coverage - YAML: 82.4% coverage
This commit is contained in:
@@ -133,6 +133,14 @@ func (w *Writer) writeSingleFile(db *models.Database) error {
|
||||
func (w *Writer) writeMultiFile(db *models.Database) error {
|
||||
packageName := w.getPackageName()
|
||||
|
||||
// Check if populate_refs is enabled
|
||||
populateRefs := false
|
||||
if w.options.Metadata != nil {
|
||||
if pr, ok := w.options.Metadata["populate_refs"].(bool); ok {
|
||||
populateRefs = pr
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure output path is a directory
|
||||
if w.options.OutputPath == "" {
|
||||
return fmt.Errorf("output path is required for multi-file mode")
|
||||
@@ -145,7 +153,16 @@ func (w *Writer) writeMultiFile(db *models.Database) error {
|
||||
|
||||
// Generate a file for each table
|
||||
for _, schema := range db.Schemas {
|
||||
// Populate RefDatabase for schema if enabled
|
||||
if populateRefs && schema.RefDatabase == nil {
|
||||
schema.RefDatabase = w.createDatabaseRef(db)
|
||||
}
|
||||
|
||||
for _, table := range schema.Tables {
|
||||
// Populate RefSchema for table if enabled
|
||||
if populateRefs && table.RefSchema == nil {
|
||||
table.RefSchema = w.createSchemaRef(schema, db)
|
||||
}
|
||||
// Create template data for this single table
|
||||
templateData := NewTemplateData(packageName, w.config)
|
||||
|
||||
@@ -322,3 +339,32 @@ func (w *Writer) writeOutput(content string) error {
|
||||
fmt.Print(content)
|
||||
return nil
|
||||
}
|
||||
|
||||
// createDatabaseRef creates a shallow copy of database without schemas to avoid circular references
|
||||
func (w *Writer) createDatabaseRef(db *models.Database) *models.Database {
|
||||
return &models.Database{
|
||||
Name: db.Name,
|
||||
Description: db.Description,
|
||||
Comment: db.Comment,
|
||||
DatabaseType: db.DatabaseType,
|
||||
DatabaseVersion: db.DatabaseVersion,
|
||||
SourceFormat: db.SourceFormat,
|
||||
Schemas: nil, // Don't include schemas to avoid circular reference
|
||||
}
|
||||
}
|
||||
|
||||
// createSchemaRef creates a shallow copy of schema without tables to avoid circular references
|
||||
func (w *Writer) createSchemaRef(schema *models.Schema, db *models.Database) *models.Schema {
|
||||
return &models.Schema{
|
||||
Name: schema.Name,
|
||||
Description: schema.Description,
|
||||
Owner: schema.Owner,
|
||||
Permissions: schema.Permissions,
|
||||
Comment: schema.Comment,
|
||||
Metadata: schema.Metadata,
|
||||
Scripts: schema.Scripts,
|
||||
Sequence: schema.Sequence,
|
||||
RefDatabase: w.createDatabaseRef(db), // Include database ref
|
||||
Tables: nil, // Don't include tables to avoid circular reference
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user