q-koa 13.2.3 → 13.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,25 +21,50 @@ const isSameArray = (_arr1 = [], _arr2 = [], deep = true) => {
|
|
|
21
21
|
)
|
|
22
22
|
}
|
|
23
23
|
const compareIndex = (tableIndexList, modelIndexList = [], model) => {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
const sameObject = (obj1, obj2) => {
|
|
25
|
+
return isSameArray(obj1.fields, obj2.fields, true)
|
|
26
|
+
}
|
|
27
|
+
tableIndexList = lodash.cloneDeep(
|
|
28
|
+
tableIndexList.filter((i) => i.name !== 'PRIMARY')
|
|
29
|
+
)
|
|
30
|
+
modelIndexList = lodash.cloneDeep(
|
|
31
|
+
modelIndexList.filter((i) => i.name !== 'PRIMARY')
|
|
32
|
+
)
|
|
33
|
+
if (tableIndexList.length === 0 && modelIndexList.length === 0) {
|
|
34
|
+
return {
|
|
35
|
+
isSame: true,
|
|
36
|
+
current: [],
|
|
37
|
+
remote: [],
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const flag = tableIndexList.every((i) => {
|
|
42
|
+
return modelIndexList.some((m) => isSameArray(m.fields, i.fields, true))
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const intersection = lodash.intersectionWith(
|
|
46
|
+
tableIndexList,
|
|
47
|
+
modelIndexList,
|
|
48
|
+
sameObject
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
const remote = tableIndexList
|
|
52
|
+
.filter((i) => {
|
|
53
|
+
return !intersection.some((inter) =>
|
|
54
|
+
isSameArray(inter.fields, i.fields, true)
|
|
55
|
+
)
|
|
56
|
+
})
|
|
57
|
+
.map((i) => lodash.pick(i, ['fields', 'name']))
|
|
58
|
+
|
|
59
|
+
const current = modelIndexList
|
|
60
|
+
.filter((i) => {
|
|
61
|
+
return !intersection.some((inter) =>
|
|
62
|
+
isSameArray(inter.fields, i.fields, true)
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
.map((i) => lodash.pick(i, ['fields', 'name']))
|
|
41
66
|
|
|
42
|
-
return flag
|
|
67
|
+
return { isSame: flag, remote, current }
|
|
43
68
|
}
|
|
44
69
|
|
|
45
70
|
exports.initModel = async (ctx) => {
|
|
@@ -793,15 +818,12 @@ exports.checkIndex = async (ctx) => {
|
|
|
793
818
|
})
|
|
794
819
|
const modelIndexList = app.config[current].indexList
|
|
795
820
|
|
|
796
|
-
const
|
|
797
|
-
if (isSame) {
|
|
821
|
+
const compareResult = compareIndex(tableIndexList, modelIndexList)
|
|
822
|
+
if (compareResult.isSame) {
|
|
798
823
|
} else {
|
|
799
824
|
res = {
|
|
800
825
|
...res,
|
|
801
|
-
[current]:
|
|
802
|
-
isSame,
|
|
803
|
-
indexList: tableIndexList.filter((i) => i.name !== 'PRIMARY'),
|
|
804
|
-
},
|
|
826
|
+
[current]: compareResult,
|
|
805
827
|
}
|
|
806
828
|
}
|
|
807
829
|
} catch (e) {
|
|
@@ -817,13 +839,9 @@ exports.checkIndex = async (ctx) => {
|
|
|
817
839
|
|
|
818
840
|
const modelIndexList = app.config[model].indexList
|
|
819
841
|
|
|
820
|
-
const
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
...(isSame
|
|
824
|
-
? {}
|
|
825
|
-
: { indexList: tableIndexList.filter((i) => i.name !== 'PRIMARY') }),
|
|
826
|
-
})
|
|
842
|
+
const compareResult = compareIndex(tableIndexList, modelIndexList)
|
|
843
|
+
|
|
844
|
+
return ctx.SUCCESS(compareResult)
|
|
827
845
|
}
|
|
828
846
|
}
|
|
829
847
|
|