gg-mysql-connector 1.0.96 → 1.0.98
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.
|
@@ -178,14 +178,20 @@ class MyDBMigrator {
|
|
|
178
178
|
const data = this.onetimeLoadColumnContent.find((row) => row.COLUMN_NAME === columnName && row.TABLE_NAME === tableName);
|
|
179
179
|
if (data) {
|
|
180
180
|
if ((data.COLUMN_KEY === "UNI" && !IS_UNIQUE) ||
|
|
181
|
-
(data.COLUMN_KEY !== "UNI" && IS_UNIQUE === true))
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
(data.COLUMN_KEY !== "UNI" && IS_UNIQUE === true)) {
|
|
182
|
+
const uniqueIndexName = `${columnName}_unique`;
|
|
183
|
+
const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
|
|
184
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === uniqueIndexName)
|
|
185
|
+
? true
|
|
186
|
+
: false;
|
|
187
|
+
if (IS_UNIQUE === true && isFound === false) {
|
|
188
|
+
await this.MyDB.query(`ALTER TABLE ${tableName} ADD CONSTRAINT ${uniqueIndexName} UNIQUE (${columnName});`);
|
|
184
189
|
}
|
|
185
|
-
else {
|
|
190
|
+
else if (IS_UNIQUE === false && isFound === true) {
|
|
186
191
|
//! DROP INDEX ถูกแล้ว อย่าแก้เป็น UNIQUE
|
|
187
|
-
await this.MyDB.query(`ALTER TABLE ${tableName} DROP INDEX ${
|
|
192
|
+
await this.MyDB.query(`ALTER TABLE ${tableName} DROP INDEX ${uniqueIndexName};`);
|
|
188
193
|
}
|
|
194
|
+
}
|
|
189
195
|
}
|
|
190
196
|
}
|
|
191
197
|
async alterIndex(tableName, columnName, IS_INDEX) {
|
|
@@ -193,13 +199,17 @@ class MyDBMigrator {
|
|
|
193
199
|
const data = this.onetimeLoadColumnContent.find((row) => row.COLUMN_NAME === columnName && row.TABLE_NAME === tableName);
|
|
194
200
|
if (data) {
|
|
195
201
|
if ((data.COLUMN_KEY === "MUL" && !IS_INDEX) ||
|
|
196
|
-
(data.COLUMN_KEY !== "MUL" && IS_INDEX === true))
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
202
|
+
(data.COLUMN_KEY !== "MUL" && IS_INDEX === true)) {
|
|
203
|
+
const indexIndexName = `${columnName}_index`;
|
|
204
|
+
const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
|
|
205
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
|
|
206
|
+
? true
|
|
207
|
+
: false;
|
|
208
|
+
if (IS_INDEX === true && isFound === false)
|
|
209
|
+
await this.MyDB.query(`ALTER TABLE ${tableName} ADD INDEX ${indexIndexName} (${columnName});`);
|
|
210
|
+
else if (IS_INDEX === false && isFound === true)
|
|
211
|
+
await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`);
|
|
212
|
+
}
|
|
203
213
|
}
|
|
204
214
|
}
|
|
205
215
|
async alterPossibleEnum(tableName, columnName, possibleValue, isNotNull) {
|
|
@@ -227,6 +237,7 @@ class MyDBMigrator {
|
|
|
227
237
|
async migrateView_v2(viewModel) {
|
|
228
238
|
let unSuccessUpdateViewList = viewModel;
|
|
229
239
|
let loopCount = 0;
|
|
240
|
+
let lastUnUpdateViewCount = unSuccessUpdateViewList.length;
|
|
230
241
|
while (unSuccessUpdateViewList.length > 0) {
|
|
231
242
|
for (const viewRow of unSuccessUpdateViewList) {
|
|
232
243
|
const content = viewRow.sqlStatement;
|
|
@@ -243,10 +254,18 @@ class MyDBMigrator {
|
|
|
243
254
|
console.log("");
|
|
244
255
|
});
|
|
245
256
|
}
|
|
246
|
-
if (
|
|
247
|
-
console.error("error
|
|
257
|
+
if (lastUnUpdateViewCount === unSuccessUpdateViewList.length) {
|
|
258
|
+
console.error("error no view update success");
|
|
248
259
|
process.exit(1);
|
|
249
260
|
}
|
|
261
|
+
else
|
|
262
|
+
lastUnUpdateViewCount = unSuccessUpdateViewList.length;
|
|
263
|
+
// if (loopCount > viewModel.length * 5) {
|
|
264
|
+
// console.error(
|
|
265
|
+
// "error while updating view, reason is loop update counter is over 5 time fail"
|
|
266
|
+
// )
|
|
267
|
+
// process.exit(1)
|
|
268
|
+
// }
|
|
250
269
|
loopCount++;
|
|
251
270
|
}
|
|
252
271
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gg-mysql-connector",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.98",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^22.7.5",
|
|
22
|
-
"typescript": "^5.
|
|
22
|
+
"typescript": "^5.9.3"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -270,17 +270,27 @@ export default class MyDBMigrator {
|
|
|
270
270
|
if (
|
|
271
271
|
(data.COLUMN_KEY === "UNI" && !IS_UNIQUE) ||
|
|
272
272
|
(data.COLUMN_KEY !== "UNI" && IS_UNIQUE === true)
|
|
273
|
-
)
|
|
274
|
-
|
|
273
|
+
) {
|
|
274
|
+
const uniqueIndexName = `${columnName}_unique`
|
|
275
|
+
const indexList = (await this.MyDB.query(
|
|
276
|
+
`SHOW INDEX FROM ${tableName}`
|
|
277
|
+
)) as { Key_name: string }[]
|
|
278
|
+
const isFound = indexList.find(
|
|
279
|
+
(iRow) => iRow.Key_name === uniqueIndexName
|
|
280
|
+
)
|
|
281
|
+
? true
|
|
282
|
+
: false
|
|
283
|
+
if (IS_UNIQUE === true && isFound === false) {
|
|
275
284
|
await this.MyDB.query(
|
|
276
|
-
`ALTER TABLE ${tableName} ADD UNIQUE (${columnName});`
|
|
285
|
+
`ALTER TABLE ${tableName} ADD CONSTRAINT ${uniqueIndexName} UNIQUE (${columnName});`
|
|
277
286
|
)
|
|
278
|
-
} else {
|
|
287
|
+
} else if (IS_UNIQUE === false && isFound === true) {
|
|
279
288
|
//! DROP INDEX ถูกแล้ว อย่าแก้เป็น UNIQUE
|
|
280
289
|
await this.MyDB.query(
|
|
281
|
-
`ALTER TABLE ${tableName} DROP INDEX ${
|
|
290
|
+
`ALTER TABLE ${tableName} DROP INDEX ${uniqueIndexName};`
|
|
282
291
|
)
|
|
283
292
|
}
|
|
293
|
+
}
|
|
284
294
|
}
|
|
285
295
|
}
|
|
286
296
|
|
|
@@ -297,14 +307,23 @@ export default class MyDBMigrator {
|
|
|
297
307
|
if (
|
|
298
308
|
(data.COLUMN_KEY === "MUL" && !IS_INDEX) ||
|
|
299
309
|
(data.COLUMN_KEY !== "MUL" && IS_INDEX === true)
|
|
300
|
-
)
|
|
301
|
-
|
|
310
|
+
) {
|
|
311
|
+
const indexIndexName = `${columnName}_index`
|
|
312
|
+
const indexList = (await this.MyDB.query(
|
|
313
|
+
`SHOW INDEX FROM ${tableName}`
|
|
314
|
+
)) as { Key_name: string }[]
|
|
315
|
+
const isFound = indexList.find(
|
|
316
|
+
(iRow) => iRow.Key_name === indexIndexName
|
|
317
|
+
)
|
|
318
|
+
? true
|
|
319
|
+
: false
|
|
320
|
+
if (IS_INDEX === true && isFound === false)
|
|
302
321
|
await this.MyDB.query(
|
|
303
|
-
`ALTER TABLE ${tableName} ADD INDEX (${columnName});`
|
|
322
|
+
`ALTER TABLE ${tableName} ADD INDEX ${indexIndexName} (${columnName});`
|
|
304
323
|
)
|
|
305
|
-
|
|
306
|
-
await this.MyDB.query(`DROP INDEX ${
|
|
307
|
-
|
|
324
|
+
else if (IS_INDEX === false && isFound === true)
|
|
325
|
+
await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`)
|
|
326
|
+
}
|
|
308
327
|
}
|
|
309
328
|
}
|
|
310
329
|
|
|
@@ -354,6 +373,7 @@ export default class MyDBMigrator {
|
|
|
354
373
|
public async migrateView_v2(viewModel: MyViewModel[]) {
|
|
355
374
|
let unSuccessUpdateViewList: MyViewModel[] = viewModel
|
|
356
375
|
let loopCount = 0
|
|
376
|
+
let lastUnUpdateViewCount = unSuccessUpdateViewList.length
|
|
357
377
|
while (unSuccessUpdateViewList.length > 0) {
|
|
358
378
|
for (const viewRow of unSuccessUpdateViewList) {
|
|
359
379
|
const content = viewRow.sqlStatement
|
|
@@ -374,12 +394,16 @@ export default class MyDBMigrator {
|
|
|
374
394
|
console.log("")
|
|
375
395
|
})
|
|
376
396
|
}
|
|
377
|
-
if (
|
|
378
|
-
console.error(
|
|
379
|
-
"error while updating view, reason is loop update counter is over 5 time fail"
|
|
380
|
-
)
|
|
397
|
+
if (lastUnUpdateViewCount === unSuccessUpdateViewList.length) {
|
|
398
|
+
console.error("error no view update success")
|
|
381
399
|
process.exit(1)
|
|
382
|
-
}
|
|
400
|
+
} else lastUnUpdateViewCount = unSuccessUpdateViewList.length
|
|
401
|
+
// if (loopCount > viewModel.length * 5) {
|
|
402
|
+
// console.error(
|
|
403
|
+
// "error while updating view, reason is loop update counter is over 5 time fail"
|
|
404
|
+
// )
|
|
405
|
+
// process.exit(1)
|
|
406
|
+
// }
|
|
383
407
|
loopCount++
|
|
384
408
|
}
|
|
385
409
|
}
|