gg-mysql-connector 1.0.102 → 1.0.104

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/app_INF.ts CHANGED
@@ -5,6 +5,11 @@ export default interface app_INF { item : {
5
5
  description: string;
6
6
  amount: number;
7
7
  userId: number; }
8
+ item__stock : {
9
+ id: number;
10
+ userId: number;
11
+ itemId: number;
12
+ amount: number; }
8
13
  user : {
9
14
  id: number;
10
15
  name: string; }
@@ -5,7 +5,11 @@
5
5
  price: "number",
6
6
  description: "string",
7
7
  amount: "number",
8
- userId: "number", }, user : {
8
+ userId: "number", }, item__stock : {
9
+ id: "number",
10
+ userId: "number",
11
+ itemId: "number",
12
+ amount: "number", }, user : {
9
13
  id: "number",
10
14
  name: "string", }, item__each_user : {
11
15
  id: "number",
package/dist/app_INF.d.ts CHANGED
@@ -7,6 +7,12 @@ export default interface app_INF {
7
7
  amount: number;
8
8
  userId: number;
9
9
  };
10
+ item__stock: {
11
+ id: number;
12
+ userId: number;
13
+ itemId: number;
14
+ amount: number;
15
+ };
10
16
  user: {
11
17
  id: number;
12
18
  name: string;
@@ -7,6 +7,12 @@ export declare const app_model_const: {
7
7
  readonly amount: "number";
8
8
  readonly userId: "number";
9
9
  };
10
+ readonly item__stock: {
11
+ readonly id: "number";
12
+ readonly userId: "number";
13
+ readonly itemId: "number";
14
+ readonly amount: "number";
15
+ };
10
16
  readonly user: {
11
17
  readonly id: "number";
12
18
  readonly name: "string";
@@ -8,6 +8,11 @@ exports.app_model_const = { item: {
8
8
  description: "string",
9
9
  amount: "number",
10
10
  userId: "number",
11
+ }, item__stock: {
12
+ id: "number",
13
+ userId: "number",
14
+ itemId: "number",
15
+ amount: "number",
11
16
  }, user: {
12
17
  id: "number",
13
18
  name: "string",
@@ -26,6 +26,7 @@ export default class MyDBMigrator {
26
26
  private checkIsColumnDataTypeChange;
27
27
  private alterUniqueKey;
28
28
  private alterIndex;
29
+ private deleteOldIndexVersion;
29
30
  private alterPossibleEnum;
30
31
  migrateView_v2(viewModel: MyViewModel[]): Promise<void>;
31
32
  private checkIsPrimaryKey;
@@ -20,12 +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);
30
+ //!! delete this next version. need to execute only 1 time on production
31
+ await this.deleteOldIndexVersion(row.tableName, col.COLUMN_NAME, indexList);
29
32
  await this.alterPossibleEnum(row.tableName, col.COLUMN_NAME, col.POSSIBLE_VALUE, col.IS_NOT_NULL);
30
33
  await this.alterForeignKey(row.tableName, col);
31
34
  }
@@ -167,11 +170,10 @@ class MyDBMigrator {
167
170
  return true;
168
171
  }
169
172
  }
170
- async alterUniqueKey(tableName, columnName, IS_UNIQUE) {
173
+ async alterUniqueKey(tableName, columnName, IS_UNIQUE, indexList) {
171
174
  console.log("alterUniqueKey()");
172
175
  const isUnique = Boolean(IS_UNIQUE);
173
176
  const uniqueIndexName = `${columnName}_unique`;
174
- const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
175
177
  const isFound = indexList.find((iRow) => iRow.Key_name === uniqueIndexName)
176
178
  ? true
177
179
  : false;
@@ -183,11 +185,10 @@ class MyDBMigrator {
183
185
  await this.MyDB.query(`ALTER TABLE ${tableName} DROP INDEX ${uniqueIndexName};`);
184
186
  }
185
187
  }
186
- async alterIndex(tableName, columnName, IS_INDEX) {
188
+ async alterIndex(tableName, columnName, IS_INDEX, indexList) {
187
189
  console.log("alterIndex()");
188
190
  const isIndex = Boolean(IS_INDEX);
189
191
  const indexIndexName = `${columnName}_index`;
190
- const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
191
192
  const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
192
193
  ? true
193
194
  : false;
@@ -196,6 +197,15 @@ class MyDBMigrator {
196
197
  else if (isIndex === false && isFound === true)
197
198
  await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`);
198
199
  }
200
+ async deleteOldIndexVersion(tableName, columnName, indexList) {
201
+ console.log("deleteOldIndexVersion()");
202
+ const indexIndexName = `${columnName}`;
203
+ const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
204
+ ? true
205
+ : false;
206
+ if (isFound === true)
207
+ await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`);
208
+ }
199
209
  async alterPossibleEnum(tableName, columnName, possibleValue, isNotNull) {
200
210
  console.log("alterPossibleEnum()");
201
211
  if (!possibleValue)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-mysql-connector",
3
- "version": "1.0.102",
3
+ "version": "1.0.104",
4
4
  "description": "",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {
@@ -35,12 +35,33 @@ 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
+ )
58
+ //!! delete this next version. need to execute only 1 time on production
59
+ await this.deleteOldIndexVersion(
60
+ row.tableName,
61
+ col.COLUMN_NAME,
62
+ indexList
63
+ )
64
+
44
65
  await this.alterPossibleEnum(
45
66
  row.tableName,
46
67
  col.COLUMN_NAME,
@@ -254,14 +275,12 @@ export default class MyDBMigrator {
254
275
  private async alterUniqueKey(
255
276
  tableName: string,
256
277
  columnName: string,
257
- IS_UNIQUE: boolean | undefined
278
+ IS_UNIQUE: boolean | undefined,
279
+ indexList: { Key_name: string }[]
258
280
  ) {
259
281
  console.log("alterUniqueKey()")
260
282
  const isUnique = Boolean(IS_UNIQUE)
261
283
  const uniqueIndexName = `${columnName}_unique`
262
- const indexList = (await this.MyDB.query(
263
- `SHOW INDEX FROM ${tableName}`
264
- )) as { Key_name: string }[]
265
284
  const isFound = indexList.find((iRow) => iRow.Key_name === uniqueIndexName)
266
285
  ? true
267
286
  : false
@@ -280,15 +299,12 @@ export default class MyDBMigrator {
280
299
  private async alterIndex(
281
300
  tableName: string,
282
301
  columnName: string,
283
- IS_INDEX: boolean | undefined
302
+ IS_INDEX: boolean | undefined,
303
+ indexList: { Key_name: string }[]
284
304
  ) {
285
305
  console.log("alterIndex()")
286
306
  const isIndex = Boolean(IS_INDEX)
287
-
288
307
  const indexIndexName = `${columnName}_index`
289
- const indexList = (await this.MyDB.query(
290
- `SHOW INDEX FROM ${tableName}`
291
- )) as { Key_name: string }[]
292
308
  const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
293
309
  ? true
294
310
  : false
@@ -300,6 +316,21 @@ export default class MyDBMigrator {
300
316
  await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`)
301
317
  }
302
318
 
319
+ private async deleteOldIndexVersion(
320
+ tableName: string,
321
+ columnName: string,
322
+ indexList: { Key_name: string }[]
323
+ ) {
324
+ console.log("deleteOldIndexVersion()")
325
+ const indexIndexName = `${columnName}`
326
+ const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
327
+ ? true
328
+ : false
329
+
330
+ if (isFound === true)
331
+ await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`)
332
+ }
333
+
303
334
  private async alterPossibleEnum(
304
335
  tableName: string,
305
336
  columnName: string,