gg-mysql-connector 1.0.103 → 1.0.106

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.
@@ -76,7 +76,7 @@ class ModelGenerator {
76
76
  const endTime = new Date();
77
77
  const executionTime = endTime.getTime() - startTime.getTime();
78
78
  if (this.isForcePrintSQLStatement === true) {
79
- console.log("sql query > ", chalk_1.default.green(statment), parameter);
79
+ console.log(`(${this.dbInfo.database}) sql query > `, chalk_1.default.green(statment), parameter);
80
80
  }
81
81
  if (isPrint === true)
82
82
  this.printResultLength(result, executionTime, queryResult);
@@ -20,14 +20,15 @@ class MyDBMigrator {
20
20
  this.onetimeLoadColumnContent = [];
21
21
  await this.loadColumnContentIfEmpty();
22
22
  index++;
23
+ const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${row.tableName}`));
23
24
  for (let col of row.columns) {
24
25
  console.log(`${row.tableName} (${col.DATA_TYPE}) - ${col.COLUMN_NAME} `);
25
26
  await this.alterPrimaryKey(row.tableName, col);
26
27
  await this.alterDataType(row.tableName, col);
27
- await this.alterUniqueKey(row.tableName, col.COLUMN_NAME, col.IS_UNIQUE);
28
- await this.alterIndex(row.tableName, col.COLUMN_NAME, col.IS_INDEX);
28
+ await this.alterUniqueKey(row.tableName, col.COLUMN_NAME, col.IS_UNIQUE, indexList);
29
+ await this.alterIndex(row.tableName, col.COLUMN_NAME, col.IS_INDEX, indexList);
29
30
  //!! delete this next version. need to execute only 1 time on production
30
- await this.deleteOldIndexVersion(row.tableName, col.COLUMN_NAME);
31
+ await this.deleteOldIndexVersion(row.tableName, col.COLUMN_NAME, indexList);
31
32
  await this.alterPossibleEnum(row.tableName, col.COLUMN_NAME, col.POSSIBLE_VALUE, col.IS_NOT_NULL);
32
33
  await this.alterForeignKey(row.tableName, col);
33
34
  }
@@ -169,11 +170,10 @@ class MyDBMigrator {
169
170
  return true;
170
171
  }
171
172
  }
172
- async alterUniqueKey(tableName, columnName, IS_UNIQUE) {
173
+ async alterUniqueKey(tableName, columnName, IS_UNIQUE, indexList) {
173
174
  console.log("alterUniqueKey()");
174
175
  const isUnique = Boolean(IS_UNIQUE);
175
176
  const uniqueIndexName = `${columnName}_unique`;
176
- const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
177
177
  const isFound = indexList.find((iRow) => iRow.Key_name === uniqueIndexName)
178
178
  ? true
179
179
  : false;
@@ -185,11 +185,10 @@ class MyDBMigrator {
185
185
  await this.MyDB.query(`ALTER TABLE ${tableName} DROP INDEX ${uniqueIndexName};`);
186
186
  }
187
187
  }
188
- async alterIndex(tableName, columnName, IS_INDEX) {
188
+ async alterIndex(tableName, columnName, IS_INDEX, indexList) {
189
189
  console.log("alterIndex()");
190
190
  const isIndex = Boolean(IS_INDEX);
191
191
  const indexIndexName = `${columnName}_index`;
192
- const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
193
192
  const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
194
193
  ? true
195
194
  : false;
@@ -198,10 +197,9 @@ class MyDBMigrator {
198
197
  else if (isIndex === false && isFound === true)
199
198
  await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`);
200
199
  }
201
- async deleteOldIndexVersion(tableName, columnName) {
200
+ async deleteOldIndexVersion(tableName, columnName, indexList) {
202
201
  console.log("deleteOldIndexVersion()");
203
202
  const indexIndexName = `${columnName}`;
204
- const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
205
203
  const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
206
204
  ? true
207
205
  : false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-mysql-connector",
3
- "version": "1.0.103",
3
+ "version": "1.0.106",
4
4
  "description": "",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {
@@ -84,7 +84,11 @@ export default class ModelGenerator {
84
84
  const executionTime = endTime.getTime() - startTime.getTime()
85
85
 
86
86
  if (this.isForcePrintSQLStatement === true) {
87
- console.log("sql query > ", chalk.green(statment), parameter)
87
+ console.log(
88
+ `(${this.dbInfo.database}) sql query > `,
89
+ chalk.green(statment),
90
+ parameter
91
+ )
88
92
  }
89
93
  if (isPrint === true)
90
94
  this.printResultLength(result, executionTime, queryResult)
@@ -35,14 +35,32 @@ export default class MyDBMigrator {
35
35
  await this.loadColumnContentIfEmpty()
36
36
  index++
37
37
 
38
+ const indexList = (await this.MyDB.query(
39
+ `SHOW INDEX FROM ${row.tableName}`
40
+ )) as { Key_name: string }[]
41
+
38
42
  for (let col of row.columns) {
39
43
  console.log(`${row.tableName} (${col.DATA_TYPE}) - ${col.COLUMN_NAME} `)
40
44
  await this.alterPrimaryKey(row.tableName, col)
41
45
  await this.alterDataType(row.tableName, col)
42
- await this.alterUniqueKey(row.tableName, col.COLUMN_NAME, col.IS_UNIQUE)
43
- await this.alterIndex(row.tableName, col.COLUMN_NAME, col.IS_INDEX)
46
+ await this.alterUniqueKey(
47
+ row.tableName,
48
+ col.COLUMN_NAME,
49
+ col.IS_UNIQUE,
50
+ indexList
51
+ )
52
+ await this.alterIndex(
53
+ row.tableName,
54
+ col.COLUMN_NAME,
55
+ col.IS_INDEX,
56
+ indexList
57
+ )
44
58
  //!! delete this next version. need to execute only 1 time on production
45
- await this.deleteOldIndexVersion(row.tableName, col.COLUMN_NAME)
59
+ await this.deleteOldIndexVersion(
60
+ row.tableName,
61
+ col.COLUMN_NAME,
62
+ indexList
63
+ )
46
64
 
47
65
  await this.alterPossibleEnum(
48
66
  row.tableName,
@@ -257,14 +275,12 @@ export default class MyDBMigrator {
257
275
  private async alterUniqueKey(
258
276
  tableName: string,
259
277
  columnName: string,
260
- IS_UNIQUE: boolean | undefined
278
+ IS_UNIQUE: boolean | undefined,
279
+ indexList: { Key_name: string }[]
261
280
  ) {
262
281
  console.log("alterUniqueKey()")
263
282
  const isUnique = Boolean(IS_UNIQUE)
264
283
  const uniqueIndexName = `${columnName}_unique`
265
- const indexList = (await this.MyDB.query(
266
- `SHOW INDEX FROM ${tableName}`
267
- )) as { Key_name: string }[]
268
284
  const isFound = indexList.find((iRow) => iRow.Key_name === uniqueIndexName)
269
285
  ? true
270
286
  : false
@@ -283,15 +299,12 @@ export default class MyDBMigrator {
283
299
  private async alterIndex(
284
300
  tableName: string,
285
301
  columnName: string,
286
- IS_INDEX: boolean | undefined
302
+ IS_INDEX: boolean | undefined,
303
+ indexList: { Key_name: string }[]
287
304
  ) {
288
305
  console.log("alterIndex()")
289
306
  const isIndex = Boolean(IS_INDEX)
290
-
291
307
  const indexIndexName = `${columnName}_index`
292
- const indexList = (await this.MyDB.query(
293
- `SHOW INDEX FROM ${tableName}`
294
- )) as { Key_name: string }[]
295
308
  const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
296
309
  ? true
297
310
  : false
@@ -303,13 +316,13 @@ export default class MyDBMigrator {
303
316
  await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`)
304
317
  }
305
318
 
306
- private async deleteOldIndexVersion(tableName: string, columnName: string) {
319
+ private async deleteOldIndexVersion(
320
+ tableName: string,
321
+ columnName: string,
322
+ indexList: { Key_name: string }[]
323
+ ) {
307
324
  console.log("deleteOldIndexVersion()")
308
-
309
325
  const indexIndexName = `${columnName}`
310
- const indexList = (await this.MyDB.query(
311
- `SHOW INDEX FROM ${tableName}`
312
- )) as { Key_name: string }[]
313
326
  const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
314
327
  ? true
315
328
  : false