Merge pull request #615 from ejulio-ts/gh-1967-column-index
compiler: Fix table prefix check
This commit is contained in:
commit
6e8ffb529f
4 changed files with 1191 additions and 2 deletions
|
|
@ -13,3 +13,4 @@
|
|||
- Watch mode only fits to screen on initial load. [#601](https://github.com/terrastruct/d2/pull/601)
|
||||
- Dimensions (`width`/`height`) were incorrectly giving compiler errors when applied on a shape with style. [#614](https://github.com/terrastruct/d2/pull/614)
|
||||
- `near` would collide with labels if they were on the diagram boundaries in the same position. [#617](https://github.com/terrastruct/d2/pull/617)
|
||||
- Fixes routing between sql table columns if the column name is the prefix of the table name [#615](https://github.com/terrastruct/d2/pull/615)
|
||||
|
|
|
|||
|
|
@ -666,7 +666,7 @@ func (c *compiler) compileSQLTable(obj *d2graph.Object) {
|
|||
obj.SQLTable = &d2target.SQLTable{}
|
||||
|
||||
parentID := obj.Parent.AbsID()
|
||||
tableID := obj.AbsID()
|
||||
tableIDPrefix := obj.AbsID() + "."
|
||||
for _, col := range obj.ChildrenArray {
|
||||
if col.IDVal == "style" {
|
||||
continue
|
||||
|
|
@ -702,7 +702,7 @@ func (c *compiler) compileSQLTable(obj *d2graph.Object) {
|
|||
srcID := e.Src.AbsID()
|
||||
dstID := e.Dst.AbsID()
|
||||
// skip edges between columns of the same table
|
||||
if strings.HasPrefix(srcID, tableID) && strings.HasPrefix(dstID, tableID) {
|
||||
if strings.HasPrefix(srcID, tableIDPrefix) && strings.HasPrefix(dstID, tableIDPrefix) {
|
||||
continue
|
||||
}
|
||||
if srcID == absID {
|
||||
|
|
|
|||
|
|
@ -1852,6 +1852,31 @@ choo: {
|
|||
expErr: `d2/testdata/d2compiler/TestCompile/sql-panic.d2:3:27: constraint value must be a string
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "wrong_column_index",
|
||||
text: `Chinchillas: {
|
||||
shape: sql_table
|
||||
id: int {constraint: primary_key}
|
||||
whisker_len: int
|
||||
fur_color: string
|
||||
age: int
|
||||
server: int {constraint: foreign_key}
|
||||
caretaker: int {constraint: foreign_key}
|
||||
}
|
||||
|
||||
Chinchillas_Collectibles: {
|
||||
shape: sql_table
|
||||
id: int
|
||||
collectible: id {constraint: foreign_key}
|
||||
chinchilla: id {constraint: foreign_key}
|
||||
}
|
||||
|
||||
Chinchillas_Collectibles.chinchilla -> Chinchillas.id`,
|
||||
assertions: func(t *testing.T, g *d2graph.Graph) {
|
||||
tassert.Equal(t, 0, *g.Edges[0].DstTableColumnIndex)
|
||||
tassert.Equal(t, 2, *g.Edges[0].SrcTableColumnIndex)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
|||
1163
testdata/d2compiler/TestCompile/wrong_column_index.exp.json
generated
vendored
Normal file
1163
testdata/d2compiler/TestCompile/wrong_column_index.exp.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue