q-koa 13.2.3 → 13.2.5
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,72 @@ 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 }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
exports.countAndMaxId = async (ctx, _data) => {
|
|
71
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
72
|
+
const { model } = ctx.request.body
|
|
73
|
+
if (!model) {
|
|
74
|
+
ctx.SUCCESS(null)
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
const count = await app.model[model].count()
|
|
78
|
+
const result = await app.model[model].findOne({
|
|
79
|
+
attributes: ['id'],
|
|
80
|
+
order: [['id', 'DESC']],
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const payLoad = {
|
|
84
|
+
count,
|
|
85
|
+
max_id: result ? result.id : 0,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ctx.SUCCESS(payLoad)
|
|
89
|
+
return payLoad
|
|
43
90
|
}
|
|
44
91
|
|
|
45
92
|
exports.initModel = async (ctx) => {
|
|
@@ -793,15 +840,12 @@ exports.checkIndex = async (ctx) => {
|
|
|
793
840
|
})
|
|
794
841
|
const modelIndexList = app.config[current].indexList
|
|
795
842
|
|
|
796
|
-
const
|
|
797
|
-
if (isSame) {
|
|
843
|
+
const compareResult = compareIndex(tableIndexList, modelIndexList)
|
|
844
|
+
if (compareResult.isSame) {
|
|
798
845
|
} else {
|
|
799
846
|
res = {
|
|
800
847
|
...res,
|
|
801
|
-
[current]:
|
|
802
|
-
isSame,
|
|
803
|
-
indexList: tableIndexList.filter((i) => i.name !== 'PRIMARY'),
|
|
804
|
-
},
|
|
848
|
+
[current]: compareResult,
|
|
805
849
|
}
|
|
806
850
|
}
|
|
807
851
|
} catch (e) {
|
|
@@ -817,13 +861,9 @@ exports.checkIndex = async (ctx) => {
|
|
|
817
861
|
|
|
818
862
|
const modelIndexList = app.config[model].indexList
|
|
819
863
|
|
|
820
|
-
const
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
...(isSame
|
|
824
|
-
? {}
|
|
825
|
-
: { indexList: tableIndexList.filter((i) => i.name !== 'PRIMARY') }),
|
|
826
|
-
})
|
|
864
|
+
const compareResult = compareIndex(tableIndexList, modelIndexList)
|
|
865
|
+
|
|
866
|
+
return ctx.SUCCESS(compareResult)
|
|
827
867
|
}
|
|
828
868
|
}
|
|
829
869
|
|