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:
@@ -125,7 +125,7 @@ func (w *Writer) tableToDBML(t *models.Table, schemaName string) string {
|
||||
// Add column attributes
|
||||
attrs := make([]string, 0)
|
||||
if column.IsPrimaryKey {
|
||||
attrs = append(attrs, "primary key")
|
||||
attrs = append(attrs, "pk")
|
||||
}
|
||||
if column.NotNull && !column.IsPrimaryKey {
|
||||
attrs = append(attrs, "not null")
|
||||
@@ -202,10 +202,23 @@ func (w *Writer) constraintToDBML(c *models.Constraint, schemaName, tableName st
|
||||
// For foreign keys, it's typically many-to-one
|
||||
relationship := ">"
|
||||
|
||||
fromCols := strings.Join(c.Columns, ", ")
|
||||
toCols := strings.Join(c.ReferencedColumns, ", ")
|
||||
// Build from and to column references
|
||||
// For single columns: table.column
|
||||
// For multiple columns: table.(col1, col2)
|
||||
var fromRef, toRef string
|
||||
if len(c.Columns) == 1 {
|
||||
fromRef = fmt.Sprintf("%s.%s", fromTable, c.Columns[0])
|
||||
} else {
|
||||
fromRef = fmt.Sprintf("%s.(%s)", fromTable, strings.Join(c.Columns, ", "))
|
||||
}
|
||||
|
||||
result := fmt.Sprintf("Ref: %s.(%s) %s %s.(%s)", fromTable, fromCols, relationship, toTable, toCols)
|
||||
if len(c.ReferencedColumns) == 1 {
|
||||
toRef = fmt.Sprintf("%s.%s", toTable, c.ReferencedColumns[0])
|
||||
} else {
|
||||
toRef = fmt.Sprintf("%s.(%s)", toTable, strings.Join(c.ReferencedColumns, ", "))
|
||||
}
|
||||
|
||||
result := fmt.Sprintf("Ref: %s %s %s", fromRef, relationship, toRef)
|
||||
|
||||
// Add actions
|
||||
actions := make([]string, 0)
|
||||
|
||||
Reference in New Issue
Block a user