feat(dbml): support multiline table notes in DBML
* Add parsing for triple-quoted table notes in DBML * Update writer to format multiline notes correctly * Enhance tests for multiline table notes handling
This commit is contained in:
@@ -1033,3 +1033,32 @@ func TestReader_ColumnPKOrderPreserved(t *testing.T) {
|
||||
t.Errorf("expected snapshot_id (declared first) to have a lower Sequence than artifact_id, got %d >= %d", snapshotCol.Sequence, artifactCol.Sequence)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReader_MultilineTableNote(t *testing.T) {
|
||||
dbmlContent := "Table \"info\".\"city\" {\n" +
|
||||
" \"id_city\" serial [pk, not null, increment]\n" +
|
||||
" \"name\" text [not null]\n\n" +
|
||||
" Note: '''\n" +
|
||||
" Cities and municipalities worldwide.\n\n" +
|
||||
" SPATIAL:\n" +
|
||||
" Proximity queries use a GiST index.\n" +
|
||||
" '''\n" +
|
||||
"}\n"
|
||||
path := filepath.Join(t.TempDir(), "city.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 got, want := table.Description, "Cities and municipalities worldwide.\n\nSPATIAL:\nProximity queries use a GiST index."; got != want {
|
||||
t.Errorf("table description = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := len(table.Columns), 2; got != want {
|
||||
t.Errorf("column count = %d, want %d; note body must not be parsed as columns", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user