gg-mysql-connector 1.0.129 → 1.0.131
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.
|
@@ -129,7 +129,7 @@ class MyDBMigrator {
|
|
|
129
129
|
async alterPrimaryKey(tableName, col) {
|
|
130
130
|
// console.log("alterPrimaryKey()")
|
|
131
131
|
if (col.COLUMN_NAME === "id" && col.AUTO_INCREMENT === true) {
|
|
132
|
-
const isPrimaryKey = await this.checkIsPrimaryKey(tableName, col.COLUMN_NAME);
|
|
132
|
+
const isPrimaryKey = await this.checkIsPrimaryKey(this.MyDB.dbInfo.database, tableName, col.COLUMN_NAME);
|
|
133
133
|
// recheck only id
|
|
134
134
|
if (isPrimaryKey === false && col.COLUMN_NAME === "id")
|
|
135
135
|
await this.MyDB.query(`ALTER TABLE ${tableName} ADD PRIMARY KEY(id);`);
|
|
@@ -274,15 +274,17 @@ class MyDBMigrator {
|
|
|
274
274
|
loopCount++;
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
|
-
async checkIsPrimaryKey(tableName, columnName) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const result2 = this.onetimeLoadColumnContent.find(
|
|
284
|
-
|
|
285
|
-
|
|
277
|
+
async checkIsPrimaryKey(databaseName, tableName, columnName) {
|
|
278
|
+
let result = (await this.MyDB.query(`SELECT *
|
|
279
|
+
FROM INFORMATION_SCHEMA.COLUMNS
|
|
280
|
+
WHERE TABLE_SCHEMA='${databaseName}'
|
|
281
|
+
AND TABLE_NAME='${tableName}'
|
|
282
|
+
AND COLUMN_NAME='${columnName}'`));
|
|
283
|
+
// const result2 = this.onetimeLoadColumnContent.find(
|
|
284
|
+
// (row) => row.TABLE_NAME === tableName && columnName === columnName
|
|
285
|
+
// )
|
|
286
|
+
if (result.length) {
|
|
287
|
+
if (result[0].COLUMN_KEY === "PRI")
|
|
286
288
|
return true;
|
|
287
289
|
else
|
|
288
290
|
return false;
|
package/package.json
CHANGED
|
@@ -207,6 +207,7 @@ export default class MyDBMigrator {
|
|
|
207
207
|
// console.log("alterPrimaryKey()")
|
|
208
208
|
if (col.COLUMN_NAME === "id" && col.AUTO_INCREMENT === true) {
|
|
209
209
|
const isPrimaryKey = await this.checkIsPrimaryKey(
|
|
210
|
+
this.MyDB.dbInfo.database,
|
|
210
211
|
tableName,
|
|
211
212
|
col.COLUMN_NAME
|
|
212
213
|
)
|
|
@@ -413,19 +414,23 @@ export default class MyDBMigrator {
|
|
|
413
414
|
}
|
|
414
415
|
}
|
|
415
416
|
|
|
416
|
-
private async checkIsPrimaryKey(
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
417
|
+
private async checkIsPrimaryKey(
|
|
418
|
+
databaseName: string,
|
|
419
|
+
tableName: string,
|
|
420
|
+
columnName: string
|
|
421
|
+
) {
|
|
422
|
+
let result = (await this.MyDB.query(`SELECT *
|
|
423
|
+
FROM INFORMATION_SCHEMA.COLUMNS
|
|
424
|
+
WHERE TABLE_SCHEMA='${databaseName}'
|
|
425
|
+
AND TABLE_NAME='${tableName}'
|
|
426
|
+
AND COLUMN_NAME='${columnName}'`)) as { COLUMN_KEY: string }[]
|
|
422
427
|
|
|
423
|
-
const result2 = this.onetimeLoadColumnContent.find(
|
|
424
|
-
|
|
425
|
-
)
|
|
428
|
+
// const result2 = this.onetimeLoadColumnContent.find(
|
|
429
|
+
// (row) => row.TABLE_NAME === tableName && columnName === columnName
|
|
430
|
+
// )
|
|
426
431
|
|
|
427
|
-
if (
|
|
428
|
-
if (
|
|
432
|
+
if (result.length) {
|
|
433
|
+
if (result[0].COLUMN_KEY === "PRI") return true
|
|
429
434
|
else return false
|
|
430
435
|
} else return false
|
|
431
436
|
}
|