q-koa 13.2.2 → 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.
package/core/app.js CHANGED
@@ -649,10 +649,8 @@ class APP {
649
649
  ...this.app[appName].attributes,
650
650
  [folder]: _attributes,
651
651
  }
652
- const indexes = _.get(
653
- this.app[appName].config[folder],
654
- 'indexList',
655
- []
652
+ const indexes = _.cloneDeep(
653
+ _.get(this.app[appName].config[folder], 'indexList', [])
656
654
  )
657
655
 
658
656
  const instance = this.app[appName].sequelize.define(
@@ -21,25 +21,50 @@ const isSameArray = (_arr1 = [], _arr2 = [], deep = true) => {
21
21
  )
22
22
  }
23
23
  const compareIndex = (tableIndexList, modelIndexList = [], model) => {
24
- const flag =
25
- tableIndexList
26
- .filter((i) => i.name !== 'PRIMARY')
27
- .filter((i) => {
28
- return !(
29
- ((i.name.startsWith(model) &&
30
- i.fields.every((f) => i.name.includes(f))) ||
31
- modelIndexList
32
- .filter((i) => i.name !== 'PRIMARY')
33
- .some((m) => m.name === i.name)) &&
34
- modelIndexList
35
- .filter((i) => i.name !== 'PRIMARY')
36
- .some((m) => isSameArray(m.fields, i.fields, true))
37
- )
38
- }).length === 0 &&
39
- tableIndexList.filter((i) => i.name !== 'PRIMARY').length ===
40
- modelIndexList.filter((i) => i.name !== 'PRIMARY').length
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 isSame = compareIndex(tableIndexList, modelIndexList, current)
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 isSame = compareIndex(tableIndexList, modelIndexList, model)
821
- return ctx.SUCCESS({
822
- isSame,
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.2.2",
3
+ "version": "13.2.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {