Skip to content

Commit 2ae6838

Browse files
committed
primary key fixes
1 parent d17e946 commit 2ae6838

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ An Open Source alternative to dbdiagram.io, aiming to have the same basic featur
3131
+ 17. Added import json files
3232
+ 18. Added actions for refs control points (add, reset, delete)
3333
+ 19. Added diagram fit function
34-
34+
+ 20. Fix key icon positioning
35+
+ 21. Show key icon for columns in composite PK
3536

3637
## Architecture - Solution
3738

web/src/components/VDbChart/VDbField.vue

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'db-field':true,
77
'db-field__highlight': highlight,
88
'db-field__dragging': dragging,
9-
'db-field__pk': pk,
9+
'db-field__pk': pk || props.indexPk,
1010
'db-field__unique': unique,
1111
'db-field__not_null': not_null,
1212
'db-field__increment': increment,
@@ -29,13 +29,13 @@
2929
:y="size.height/2">
3030
{{ name }}
3131
</text>
32-
<svg v-if="pk" class="db-field__pk-icon" xmlns="http://www.w3.org/2000/svg" height="16" viewBox="0 -960 960 960" width="16"
33-
:x="state.name_width"
32+
<svg v-if="pk || props.indexPk" class="db-field__pk-icon" xmlns="http://www.w3.org/2000/svg" height="16" viewBox="0 -960 960 960" width="16"
33+
:x="state.name_width+3"
3434
:y="size.height/4" >
3535
<path d="M280-400q-33 0-56.5-23.5T200-480q0-33 23.5-56.5T280-560q33 0 56.5 23.5T360-480q0 33-23.5 56.5T280-400Zm0 160q-100 0-170-70T40-480q0-100 70-170t170-70q67 0 121.5 33t86.5 87h352l120 120-180 180-80-60-80 60-85-60h-47q-32 54-86.5 87T280-240Zm0-80q56 0 98.5-34t56.5-86h125l58 41 82-61 71 55 75-75-40-40H435q-14-52-56.5-86T280-640q-66 0-113 47t-47 113q0 66 47 113t113 47Z"/>
3636
</svg>
3737
<svg v-if="_enum || note || dbdefault" xmlns="http://www.w3.org/2000/svg" class="db-field__note-icon" height="16" viewBox="0 -960 960 960" width="16"
38-
:x="pk ? state.name_width + 20 : state.name_width"
38+
:x="pk || props.indexPk ? state.name_width + 20 : state.name_width+2"
3939
:y="size.height/4">
4040
<path d="M200-200h360v-200h200v-360H200v560Zm0 80q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v400L600-120H200Zm80-280v-80h200v80H280Zm0-160v-80h400v80H280Zm-80 360v-560 560Z"/>
4141
</svg>
@@ -84,6 +84,7 @@ import { useChartStore } from '../../store/chart';
8484
table: Object,
8585
endpoints: Array,
8686
_enum: Object,
87+
indexPk:Boolean
8788
})
8889
const root = ref(null)
8990
@@ -112,11 +113,11 @@ import { useChartStore } from '../../store/chart';
112113
let shift_rect_enum = 0;
113114
let shift_rect_nn = 0;
114115
if (props._enum){
115-
shift += 12;
116+
shift += 13;
116117
shift_rect_enum += 8;
117118
}
118119
if (props.not_null){
119-
shift += 22;
120+
shift += 23;
120121
shift_rect_enum +=30;
121122
shift_rect_nn += 18;
122123
}

web/src/components/VDbChart/VDbTable.vue

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<g class="db-table-fields">
4646
<v-db-field v-for="field of fields"
4747
v-bind="field"
48+
:indexPk="checkIndexPK(field)"
4849
:key="field.id"
4950
:width="state.width"
5051
@click.passive="onFieldClick($event, field)"
@@ -111,6 +112,12 @@
111112
state.value.height = 35 + (30 * props.fields.length);
112113
}
113114
115+
const checkIndexPK = (field) => {
116+
console.log(props.indexes, field)
117+
console.log(props.indexes.filter((x)=> x.columns.filter((y)=> y.type == 'column' && y.value == field.name)))
118+
return props.indexes.filter((x)=> x.columns.filter((y)=> y.type == 'column' && y.value == field.name).length > 0 && x.pk).length > 0
119+
}
120+
114121
watch(() => props.useSchema, value => {
115122
updateWidth();
116123
});

web/src/components/VDbChart/VDbTableTooltip.vue

+11-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
<div class="text-caption"><b>Indexes</b></div>
1212
<q-list>
1313
<div v-for="index of table.indexes" class="db-tip-highlights">
14-
<span>({{ index.id }}) {{index.name}} </span>
15-
<span v-if="index.type" class="enum-value_name">:[{{index.type}}]</span>
16-
<br/>
14+
<div v-if="index.name || index.type">
15+
<span v-if="index.name">{{index.name}} </span>
16+
<span v-if="index.type" class="enum-value_name">:[{{index.type}}]</span>
17+
</div>
18+
19+
1720
<div v-if="index.pk || index.unique" class="db-tip-highlights">
18-
<span class="enum-class">spec: </span>
21+
<span class="enum-class">ID: </span>
22+
<span v-if="index.id">{{ index.id }}</span>
23+
<span class="enum-class"> spec: </span>
1924
<span v-if="index.pk">PK</span>
2025
<span v-if="index.pk && index.unique">|</span>
2126
<span v-if="index.unique">UNIQUE</span>
@@ -34,7 +39,8 @@
3439
<span class="enum-class">note: </span>
3540
<span>{{ index.note }}</span>
3641
</div>
37-
</div>
42+
</div>
43+
3844
</q-list>
3945
</q-card-section>
4046

web/src/css/VDbChart/_tooltips.scss

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
pointer-events: none;
4949
display: block;
5050

51+
.db-index-tip{
52+
display: flex;
53+
flex-direction: row;
54+
}
55+
5156
.enum-value{
5257
display: block;
5358

0 commit comments

Comments
 (0)