fix(dbml): resolve commented cross-file // Ref: lines
Commented refs are collected per file and resolved against the combined model after all inputs are loaded (directory, --from-list, merge, jobs). Matched refs become FKs and relationships; duplicates of existing FKs are skipped; missing targets are skipped with a warning; column type mismatches warn. Also keep reused index names within a DBML table instead of overwriting, give a second FK to the same table a distinct relationship name, and make the pgsql writer match relationships to FKs by name first.
This commit is contained in:
@@ -1085,3 +1085,39 @@ func TestReader_MultilineTableNote(t *testing.T) {
|
||||
t.Errorf("column note = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// A name reused inside one Indexes block must not silently drop the earlier
|
||||
// index; both are kept so the inspector can report the duplicate.
|
||||
func TestReader_DuplicateIndexNameInTableKept(t *testing.T) {
|
||||
dbmlContent := `Table individual_actor {
|
||||
id bigint [pk]
|
||||
rid_actor bigint
|
||||
kind text
|
||||
|
||||
Indexes {
|
||||
(rid_actor) [name: 'idx_actor', unique]
|
||||
(rid_actor, kind) [name: 'idx_actor']
|
||||
}
|
||||
}
|
||||
`
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "dup_index.dbml")
|
||||
if err := os.WriteFile(path, []byte(dbmlContent), 0o644); err != nil {
|
||||
t.Fatalf("failed to write fixture: %v", err)
|
||||
}
|
||||
|
||||
db, err := NewReader(&readers.ReaderOptions{FilePath: path}).ReadDatabase()
|
||||
if err != nil {
|
||||
t.Fatalf("ReadDatabase() error = %v", err)
|
||||
}
|
||||
|
||||
table := db.Schemas[0].Tables[0]
|
||||
if len(table.Indexes) != 2 {
|
||||
t.Fatalf("expected 2 indexes, got %d: %v", len(table.Indexes), table.Indexes)
|
||||
}
|
||||
for key, idx := range table.Indexes {
|
||||
if idx.Name != "idx_actor" {
|
||||
t.Errorf("index %q: Name = %q, want idx_actor", key, idx.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user