gg-mysql-connector 1.0.95 → 1.0.97

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.
@@ -10,6 +10,7 @@ export default class MyDBMigrator {
10
10
  COLUMN_KEY: string;
11
11
  COLUMN_TYPE: string;
12
12
  }[];
13
+ foreignKeyStatementList: string[];
13
14
  constructor(connection: ModelGenerator);
14
15
  migrateTable(model: MyModel[]): Promise<void>;
15
16
  private isConstraintNameExist;
@@ -8,6 +8,7 @@ class MyDBMigrator {
8
8
  constructor(connection) {
9
9
  this.MyDB = connection;
10
10
  this.onetimeLoadColumnContent = [];
11
+ this.foreignKeyStatementList = [];
11
12
  }
12
13
  async migrateTable(model) {
13
14
  let data = model.filter((row) => row.tableName !== "sessions" && row.tableName.search("prisma") < 0);
@@ -30,6 +31,11 @@ class MyDBMigrator {
30
31
  }
31
32
  await this.alterColumnCombination(row.tableName, row.compoisteColumn);
32
33
  }
34
+ // execute foreignKeyStatement
35
+ console.log("execute foreignKeyStatement");
36
+ for (let row of this.foreignKeyStatementList) {
37
+ await this.MyDB.query(row);
38
+ }
33
39
  console.log("migrate table done");
34
40
  }
35
41
  async isConstraintNameExist(constraintName) {
@@ -69,12 +75,13 @@ class MyDBMigrator {
69
75
  if (constraintExist) {
70
76
  await this.MyDB.query(`ALTER TABLE ${tableName} DROP FOREIGN KEY ${CONSTRAINT}`);
71
77
  }
72
- await this.MyDB
73
- .query(`ALTER TABLE ${tableName} ADD CONSTRAINT ${CONSTRAINT}
78
+ const statement = `ALTER TABLE ${tableName} ADD CONSTRAINT ${CONSTRAINT}
74
79
  FOREIGN KEY (${col.COLUMN_NAME})
75
80
  REFERENCES ${row.tableName}(${row.columnName})
76
81
  ON DELETE ${row.ON_DELETE}
77
- ON UPDATE ${row.ON_UPDATE}`);
82
+ ON UPDATE ${row.ON_UPDATE}`;
83
+ // await this.MyDB.query(statement)
84
+ this.foreignKeyStatementList.push(statement);
78
85
  }
79
86
  }
80
87
  }
@@ -220,6 +227,7 @@ class MyDBMigrator {
220
227
  async migrateView_v2(viewModel) {
221
228
  let unSuccessUpdateViewList = viewModel;
222
229
  let loopCount = 0;
230
+ let lastUnUpdateViewCount = unSuccessUpdateViewList.length;
223
231
  while (unSuccessUpdateViewList.length > 0) {
224
232
  for (const viewRow of unSuccessUpdateViewList) {
225
233
  const content = viewRow.sqlStatement;
@@ -236,10 +244,18 @@ class MyDBMigrator {
236
244
  console.log("");
237
245
  });
238
246
  }
239
- if (loopCount > viewModel.length * 5) {
240
- console.error("error while updating view, reason is loop update counter is over 5 time fail");
247
+ if (lastUnUpdateViewCount === unSuccessUpdateViewList.length) {
248
+ console.error("error no view update success");
241
249
  process.exit(1);
242
250
  }
251
+ else
252
+ lastUnUpdateViewCount = unSuccessUpdateViewList.length;
253
+ // if (loopCount > viewModel.length * 5) {
254
+ // console.error(
255
+ // "error while updating view, reason is loop update counter is over 5 time fail"
256
+ // )
257
+ // process.exit(1)
258
+ // }
243
259
  loopCount++;
244
260
  }
245
261
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-mysql-connector",
3
- "version": "1.0.95",
3
+ "version": "1.0.97",
4
4
  "description": "",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {
@@ -13,9 +13,12 @@ export default class MyDBMigrator {
13
13
  COLUMN_KEY: string
14
14
  COLUMN_TYPE: string
15
15
  }[]
16
+ foreignKeyStatementList: string[]
17
+
16
18
  constructor(connection: ModelGenerator) {
17
19
  this.MyDB = connection
18
20
  this.onetimeLoadColumnContent = []
21
+ this.foreignKeyStatementList = []
19
22
  }
20
23
 
21
24
  async migrateTable(model: MyModel[]) {
@@ -48,6 +51,11 @@ export default class MyDBMigrator {
48
51
  }
49
52
  await this.alterColumnCombination(row.tableName, row.compoisteColumn)
50
53
  }
54
+ // execute foreignKeyStatement
55
+ console.log("execute foreignKeyStatement")
56
+ for (let row of this.foreignKeyStatementList) {
57
+ await this.MyDB.query(row)
58
+ }
51
59
  console.log("migrate table done")
52
60
  }
53
61
 
@@ -105,12 +113,13 @@ export default class MyDBMigrator {
105
113
  `ALTER TABLE ${tableName} DROP FOREIGN KEY ${CONSTRAINT}`
106
114
  )
107
115
  }
108
- await this.MyDB
109
- .query(`ALTER TABLE ${tableName} ADD CONSTRAINT ${CONSTRAINT}
116
+ const statement = `ALTER TABLE ${tableName} ADD CONSTRAINT ${CONSTRAINT}
110
117
  FOREIGN KEY (${col.COLUMN_NAME})
111
118
  REFERENCES ${row.tableName}(${row.columnName})
112
119
  ON DELETE ${row.ON_DELETE}
113
- ON UPDATE ${row.ON_UPDATE}`)
120
+ ON UPDATE ${row.ON_UPDATE}`
121
+ // await this.MyDB.query(statement)
122
+ this.foreignKeyStatementList.push(statement)
114
123
  }
115
124
  }
116
125
  }
@@ -345,6 +354,7 @@ export default class MyDBMigrator {
345
354
  public async migrateView_v2(viewModel: MyViewModel[]) {
346
355
  let unSuccessUpdateViewList: MyViewModel[] = viewModel
347
356
  let loopCount = 0
357
+ let lastUnUpdateViewCount = unSuccessUpdateViewList.length
348
358
  while (unSuccessUpdateViewList.length > 0) {
349
359
  for (const viewRow of unSuccessUpdateViewList) {
350
360
  const content = viewRow.sqlStatement
@@ -365,12 +375,16 @@ export default class MyDBMigrator {
365
375
  console.log("")
366
376
  })
367
377
  }
368
- if (loopCount > viewModel.length * 5) {
369
- console.error(
370
- "error while updating view, reason is loop update counter is over 5 time fail"
371
- )
378
+ if (lastUnUpdateViewCount === unSuccessUpdateViewList.length) {
379
+ console.error("error no view update success")
372
380
  process.exit(1)
373
- }
381
+ } else lastUnUpdateViewCount = unSuccessUpdateViewList.length
382
+ // if (loopCount > viewModel.length * 5) {
383
+ // console.error(
384
+ // "error while updating view, reason is loop update counter is over 5 time fail"
385
+ // )
386
+ // process.exit(1)
387
+ // }
374
388
  loopCount++
375
389
  }
376
390
  }