Fix table prefix check

This commit is contained in:
Júlio César Batista 2023-01-06 16:03:39 -03:00
parent 5fc2fabe1d
commit 5fc492669e
No known key found for this signature in database
GPG key ID: 10C4B861BF314878
8 changed files with 2088 additions and 2 deletions

View file

@ -666,7 +666,7 @@ func (c *compiler) compileSQLTable(obj *d2graph.Object) {
obj.SQLTable = &d2target.SQLTable{}
parentID := obj.Parent.AbsID()
tableID := obj.AbsID()
prefixTableID := 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, prefixTableID) && strings.HasPrefix(dstID, prefixTableID) {
continue
}
if srcID == absID {

View file

@ -1843,6 +1843,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 {

View file

@ -284,6 +284,27 @@ table with short col: RefreshAuthorizationPolicyCache {
class -> table -> table with short col
`,
},
{
name: "wrong_table_column",
script: `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`,
},
}
runa(t, tcs)

View file

@ -0,0 +1,394 @@
{
"name": "",
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "Chinchillas",
"type": "sql_table",
"pos": {
"x": 19,
"y": 244
},
"width": 259,
"height": 252,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#0A0F25",
"stroke": "#FFFFFF",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": [
{
"name": {
"label": "id",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 15,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "primary_key",
"reference": ""
},
{
"name": {
"label": "whisker_len",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 101,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "",
"reference": ""
},
{
"name": {
"label": "fur_color",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 77,
"labelHeight": 26
},
"type": {
"label": "string",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 48,
"labelHeight": 26
},
"constraint": "",
"reference": ""
},
{
"name": {
"label": "age",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 30,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "",
"reference": ""
},
{
"name": {
"label": "server",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 52,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "foreign_key",
"reference": ""
},
{
"name": {
"label": "caretaker",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 80,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "foreign_key",
"reference": ""
}
],
"label": "Chinchillas",
"fontSize": 20,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 120,
"labelHeight": 36,
"zIndex": 0,
"level": 1,
"primaryAccentColor": "#0D32B2",
"secondaryAccentColor": "#4A6FF3",
"neutralAccentColor": "#676C7E"
},
{
"id": "Chinchillas_Collectibles",
"type": "sql_table",
"pos": {
"x": 0,
"y": 0
},
"width": 297,
"height": 144,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#0A0F25",
"stroke": "#FFFFFF",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": [
{
"name": {
"label": "id",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 15,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "",
"reference": ""
},
{
"name": {
"label": "collectible",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 88,
"labelHeight": 26
},
"type": {
"label": "id",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 15,
"labelHeight": 26
},
"constraint": "foreign_key",
"reference": ""
},
{
"name": {
"label": "chinchilla",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 80,
"labelHeight": 26
},
"type": {
"label": "id",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 15,
"labelHeight": 26
},
"constraint": "foreign_key",
"reference": "Chinchillas.id"
}
],
"label": "Chinchillas_Collectibles",
"fontSize": 20,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 257,
"labelHeight": 36,
"zIndex": 0,
"level": 1,
"primaryAccentColor": "#0D32B2",
"secondaryAccentColor": "#4A6FF3",
"neutralAccentColor": "#676C7E"
}
],
"connections": [
{
"id": "(Chinchillas_Collectibles -> Chinchillas)[0]",
"src": "Chinchillas_Collectibles",
"srcArrow": "none",
"srcLabel": "",
"dst": "Chinchillas",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "#0D32B2",
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#676C7E",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 148.5,
"y": 144
},
{
"x": 148.5,
"y": 184
},
{
"x": 148.5,
"y": 204
},
{
"x": 148.5,
"y": 244
}
],
"isCurve": true,
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 0
}
]
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 330 KiB

View file

@ -0,0 +1,385 @@
{
"name": "",
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "Chinchillas",
"type": "sql_table",
"pos": {
"x": 31,
"y": 256
},
"width": 259,
"height": 252,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#0A0F25",
"stroke": "#FFFFFF",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": [
{
"name": {
"label": "id",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 15,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "primary_key",
"reference": ""
},
{
"name": {
"label": "whisker_len",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 101,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "",
"reference": ""
},
{
"name": {
"label": "fur_color",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 77,
"labelHeight": 26
},
"type": {
"label": "string",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 48,
"labelHeight": 26
},
"constraint": "",
"reference": ""
},
{
"name": {
"label": "age",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 30,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "",
"reference": ""
},
{
"name": {
"label": "server",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 52,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "foreign_key",
"reference": ""
},
{
"name": {
"label": "caretaker",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 80,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "foreign_key",
"reference": ""
}
],
"label": "Chinchillas",
"fontSize": 20,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 120,
"labelHeight": 36,
"zIndex": 0,
"level": 1,
"primaryAccentColor": "#0D32B2",
"secondaryAccentColor": "#4A6FF3",
"neutralAccentColor": "#676C7E"
},
{
"id": "Chinchillas_Collectibles",
"type": "sql_table",
"pos": {
"x": 12,
"y": 12
},
"width": 297,
"height": 144,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#0A0F25",
"stroke": "#FFFFFF",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": [
{
"name": {
"label": "id",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 15,
"labelHeight": 26
},
"type": {
"label": "int",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 23,
"labelHeight": 26
},
"constraint": "",
"reference": ""
},
{
"name": {
"label": "collectible",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 88,
"labelHeight": 26
},
"type": {
"label": "id",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 15,
"labelHeight": 26
},
"constraint": "foreign_key",
"reference": ""
},
{
"name": {
"label": "chinchilla",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 80,
"labelHeight": 26
},
"type": {
"label": "id",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 15,
"labelHeight": 26
},
"constraint": "foreign_key",
"reference": "Chinchillas.id"
}
],
"label": "Chinchillas_Collectibles",
"fontSize": 20,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 257,
"labelHeight": 36,
"zIndex": 0,
"level": 1,
"primaryAccentColor": "#0D32B2",
"secondaryAccentColor": "#4A6FF3",
"neutralAccentColor": "#676C7E"
}
],
"connections": [
{
"id": "(Chinchillas_Collectibles -> Chinchillas)[0]",
"src": "Chinchillas_Collectibles",
"srcArrow": "none",
"srcLabel": "",
"dst": "Chinchillas",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "#0D32B2",
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#676C7E",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 160.5,
"y": 156
},
{
"x": 160.5,
"y": 256
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 0
}
]
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 330 KiB

File diff suppressed because it is too large Load diff