@dnax/core 0.19.1 → 0.19.3
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/lib/collection.ts +23 -6
- package/package.json +1 -1
package/lib/collection.ts
CHANGED
|
@@ -64,6 +64,8 @@ async function syncCollectionDatabase() {
|
|
|
64
64
|
?.listCollections()
|
|
65
65
|
.toArray();
|
|
66
66
|
|
|
67
|
+
//t.database.db.
|
|
68
|
+
|
|
67
69
|
if (t.database.driver == "mongodb") {
|
|
68
70
|
const collections: Collection[] | undefined = Cfg.collections?.filter(
|
|
69
71
|
(cn) => cn.tenant_id == t.id
|
|
@@ -71,6 +73,7 @@ async function syncCollectionDatabase() {
|
|
|
71
73
|
|
|
72
74
|
if (collections?.length) {
|
|
73
75
|
for await (let c of collections) {
|
|
76
|
+
// boucle sur les collections
|
|
74
77
|
//console.log(c?.slug,c.init)
|
|
75
78
|
if (c?.init && typeof c?.init == "function") {
|
|
76
79
|
await c?.init({
|
|
@@ -91,13 +94,29 @@ async function syncCollectionDatabase() {
|
|
|
91
94
|
await t.database.db?.createCollection(c.slug);
|
|
92
95
|
}
|
|
93
96
|
|
|
97
|
+
// suppression d'index
|
|
98
|
+
c?.fields?.map((f) => {
|
|
99
|
+
if (f?.unique === false) {
|
|
100
|
+
let keyToremove = f?.name + "_1";
|
|
101
|
+
// console.log('keyToremove :: ',keyToremove)
|
|
102
|
+
t.database.db
|
|
103
|
+
?.collection(c.slug)
|
|
104
|
+
.dropIndex(keyToremove)
|
|
105
|
+
.catch((err) => {
|
|
106
|
+
// console.error(err);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
94
111
|
// suppression auto Removes des indexes
|
|
95
|
-
if (c?.autoRemoveIndexes?.length
|
|
112
|
+
if (c?.autoRemoveIndexes?.length) {
|
|
96
113
|
for await (let index of c?.autoRemoveIndexes || []) {
|
|
97
114
|
await t.database?.db
|
|
98
115
|
?.collection(c.slug)
|
|
99
116
|
.dropIndex(index)
|
|
100
|
-
.catch((err) => {
|
|
117
|
+
.catch((err) => {
|
|
118
|
+
// console.error(err?.message);
|
|
119
|
+
});
|
|
101
120
|
}
|
|
102
121
|
}
|
|
103
122
|
|
|
@@ -105,11 +124,9 @@ async function syncCollectionDatabase() {
|
|
|
105
124
|
?.collection(c.slug)
|
|
106
125
|
.indexes()
|
|
107
126
|
.catch((err) => {
|
|
108
|
-
console.error(err?.message);
|
|
127
|
+
// console.error(err?.message);
|
|
109
128
|
});
|
|
110
129
|
|
|
111
|
-
// console.log('Allindex',allIndexes)
|
|
112
|
-
|
|
113
130
|
for await (let dbIndex of allIndexes || []) {
|
|
114
131
|
// creation des indexes createdAt / updatedAt
|
|
115
132
|
if (!dbIndex?.key?.createdAt && !dbIndex?.key?.updatedAt) {
|
|
@@ -161,7 +178,7 @@ async function syncCollectionDatabase() {
|
|
|
161
178
|
?.collection(c.slug)
|
|
162
179
|
.dropIndex(indexHasAlready?.name)
|
|
163
180
|
.catch((err) => {
|
|
164
|
-
console.error(err?.message);
|
|
181
|
+
// console.error(err?.message);
|
|
165
182
|
});
|
|
166
183
|
}
|
|
167
184
|
|