gg-mysql-connector 1.0.131 → 1.0.132
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.
|
@@ -35,6 +35,14 @@ class ModelGenerator {
|
|
|
35
35
|
});
|
|
36
36
|
this.isConnected = true;
|
|
37
37
|
await this.createDatabaseIfNotExist();
|
|
38
|
+
await this.connection.end();
|
|
39
|
+
this.connection = await promise_1.default.createPool({
|
|
40
|
+
host: this.dbInfo.host,
|
|
41
|
+
user: this.dbInfo.user,
|
|
42
|
+
password: this.dbInfo.password,
|
|
43
|
+
port: this.dbInfo.port,
|
|
44
|
+
database: this.dbInfo.database,
|
|
45
|
+
});
|
|
38
46
|
}
|
|
39
47
|
async createDatabaseIfNotExist() {
|
|
40
48
|
const databaseName = this.dbInfo.database;
|
|
@@ -16,13 +16,13 @@ class MyDBMigrator {
|
|
|
16
16
|
async migrateTable(model) {
|
|
17
17
|
let data = model.filter((row) => row.tableName !== "sessions" && row.tableName.search("prisma") < 0);
|
|
18
18
|
let index = 1;
|
|
19
|
-
this.onetimeLoadColumnContent = [];
|
|
20
|
-
await this.loadColumnContentIfEmpty();
|
|
21
19
|
for (let row of data) {
|
|
22
20
|
console.log(chalk_1.default.bgBlue(`${index}/${data.length} ${row.tableName}`));
|
|
23
21
|
await this.createTableIfNotExist(row.tableName);
|
|
24
22
|
index++;
|
|
25
23
|
const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${row.tableName}`));
|
|
24
|
+
this.onetimeLoadColumnContent = [];
|
|
25
|
+
await this.loadColumnContentIfEmpty();
|
|
26
26
|
for (let col of row.columns) {
|
|
27
27
|
console.log(`${row.tableName} (${col.DATA_TYPE}) - ${col.COLUMN_NAME} `);
|
|
28
28
|
await this.alterPrimaryKey(row.tableName, col);
|
|
@@ -130,8 +130,7 @@ class MyDBMigrator {
|
|
|
130
130
|
// console.log("alterPrimaryKey()")
|
|
131
131
|
if (col.COLUMN_NAME === "id" && col.AUTO_INCREMENT === true) {
|
|
132
132
|
const isPrimaryKey = await this.checkIsPrimaryKey(this.MyDB.dbInfo.database, tableName, col.COLUMN_NAME);
|
|
133
|
-
|
|
134
|
-
if (isPrimaryKey === false && col.COLUMN_NAME === "id")
|
|
133
|
+
if (isPrimaryKey === false)
|
|
135
134
|
await this.MyDB.query(`ALTER TABLE ${tableName} ADD PRIMARY KEY(id);`);
|
|
136
135
|
}
|
|
137
136
|
}
|
|
@@ -280,6 +279,7 @@ class MyDBMigrator {
|
|
|
280
279
|
WHERE TABLE_SCHEMA='${databaseName}'
|
|
281
280
|
AND TABLE_NAME='${tableName}'
|
|
282
281
|
AND COLUMN_NAME='${columnName}'`));
|
|
282
|
+
// console.log("checkIsPrimaryKey", result)
|
|
283
283
|
// const result2 = this.onetimeLoadColumnContent.find(
|
|
284
284
|
// (row) => row.TABLE_NAME === tableName && columnName === columnName
|
|
285
285
|
// )
|
package/package.json
CHANGED
|
@@ -36,6 +36,14 @@ export default class ModelGenerator {
|
|
|
36
36
|
})
|
|
37
37
|
this.isConnected = true
|
|
38
38
|
await this.createDatabaseIfNotExist()
|
|
39
|
+
await this.connection.end()
|
|
40
|
+
this.connection = await mysql.createPool({
|
|
41
|
+
host: this.dbInfo.host,
|
|
42
|
+
user: this.dbInfo.user,
|
|
43
|
+
password: this.dbInfo.password,
|
|
44
|
+
port: this.dbInfo.port,
|
|
45
|
+
database: this.dbInfo.database,
|
|
46
|
+
})
|
|
39
47
|
}
|
|
40
48
|
private async createDatabaseIfNotExist() {
|
|
41
49
|
const databaseName = this.dbInfo.database
|
|
@@ -44,6 +52,7 @@ export default class ModelGenerator {
|
|
|
44
52
|
}
|
|
45
53
|
async pushModelToDB() {
|
|
46
54
|
const migrator = new MyDBMigrator(this)
|
|
55
|
+
|
|
47
56
|
await migrator.migrateTable(this.model)
|
|
48
57
|
}
|
|
49
58
|
async pushViewToDB_v2(viewModel: MyViewModel[]) {
|
|
@@ -32,8 +32,7 @@ export default class MyDBMigrator {
|
|
|
32
32
|
row.tableName !== "sessions" && row.tableName.search("prisma") < 0
|
|
33
33
|
)
|
|
34
34
|
let index = 1
|
|
35
|
-
|
|
36
|
-
await this.loadColumnContentIfEmpty()
|
|
35
|
+
|
|
37
36
|
for (let row of data) {
|
|
38
37
|
console.log(chalk.bgBlue(`${index}/${data.length} ${row.tableName}`))
|
|
39
38
|
await this.createTableIfNotExist(row.tableName)
|
|
@@ -44,6 +43,9 @@ export default class MyDBMigrator {
|
|
|
44
43
|
`SHOW INDEX FROM ${row.tableName}`
|
|
45
44
|
)) as { Key_name: string }[]
|
|
46
45
|
|
|
46
|
+
this.onetimeLoadColumnContent = []
|
|
47
|
+
await this.loadColumnContentIfEmpty()
|
|
48
|
+
|
|
47
49
|
for (let col of row.columns) {
|
|
48
50
|
console.log(`${row.tableName} (${col.DATA_TYPE}) - ${col.COLUMN_NAME} `)
|
|
49
51
|
await this.alterPrimaryKey(row.tableName, col)
|
|
@@ -211,8 +213,7 @@ export default class MyDBMigrator {
|
|
|
211
213
|
tableName,
|
|
212
214
|
col.COLUMN_NAME
|
|
213
215
|
)
|
|
214
|
-
|
|
215
|
-
if (isPrimaryKey === false && col.COLUMN_NAME === "id")
|
|
216
|
+
if (isPrimaryKey === false)
|
|
216
217
|
await this.MyDB.query(`ALTER TABLE ${tableName} ADD PRIMARY KEY(id);`)
|
|
217
218
|
}
|
|
218
219
|
}
|
|
@@ -424,7 +425,7 @@ export default class MyDBMigrator {
|
|
|
424
425
|
WHERE TABLE_SCHEMA='${databaseName}'
|
|
425
426
|
AND TABLE_NAME='${tableName}'
|
|
426
427
|
AND COLUMN_NAME='${columnName}'`)) as { COLUMN_KEY: string }[]
|
|
427
|
-
|
|
428
|
+
// console.log("checkIsPrimaryKey", result)
|
|
428
429
|
// const result2 = this.onetimeLoadColumnContent.find(
|
|
429
430
|
// (row) => row.TABLE_NAME === tableName && columnName === columnName
|
|
430
431
|
// )
|