gg-mysql-connector 1.0.95 → 1.0.96

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
  }
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.96",
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
  }