gg-mysql-connector 1.0.126 → 1.0.129
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.
|
@@ -4,6 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const chalk_1 = __importDefault(require("chalk"));
|
|
7
|
+
function keepOnlyDigits(str) {
|
|
8
|
+
return Number(str.replace(/\D/g, ""));
|
|
9
|
+
}
|
|
7
10
|
class MyDBMigrator {
|
|
8
11
|
constructor(connection) {
|
|
9
12
|
this.MyDB = connection;
|
|
@@ -151,6 +154,9 @@ class MyDBMigrator {
|
|
|
151
154
|
if (this.onetimeLoadColumnContent.length === 0) {
|
|
152
155
|
this.onetimeLoadColumnContent = (await this.MyDB.query(`SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '${this.MyDB.dbInfo.database}'`, undefined, false));
|
|
153
156
|
}
|
|
157
|
+
// const temp = this.onetimeLoadColumnContent.forEach((row)=>{
|
|
158
|
+
// if(row.COLUMN_TYPE === '')
|
|
159
|
+
// })
|
|
154
160
|
}
|
|
155
161
|
async checkIsColumnDataTypeChange(tableName, columnName, dataType, columnDefault) {
|
|
156
162
|
await this.loadColumnContentIfEmpty();
|
|
@@ -161,16 +167,18 @@ class MyDBMigrator {
|
|
|
161
167
|
columnDefault = "NULL";
|
|
162
168
|
if (temp.length > 0) {
|
|
163
169
|
if (temp[0].DATA_TYPE !== dataType) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
if (temp[0].DATA_TYPE.search("varchar") >= 0) {
|
|
171
|
+
if (temp[0].CHARACTER_MAXIMUM_LENGTH !==
|
|
172
|
+
keepOnlyDigits(temp[0].DATA_TYPE))
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
console.log(chalk_1.default.green `DATA_TYPE -> ${temp[0].DATA_TYPE} change to ${dataType}`);
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
171
179
|
}
|
|
172
180
|
if (temp[0].COLUMN_DEFAULT !== columnDefault) {
|
|
173
|
-
console.log(chalk_1.default.green
|
|
181
|
+
console.log(chalk_1.default.green `COLUMN_DEFAULT -> ${temp[0].COLUMN_DEFAULT} change to ${columnDefault}`);
|
|
174
182
|
return true;
|
|
175
183
|
}
|
|
176
184
|
return false;
|
package/package.json
CHANGED
|
@@ -4,6 +4,9 @@ import ModelGenerator from "../ModelGenerator/ModelGenerator"
|
|
|
4
4
|
import { columnType, MyModel, MyViewModel } from "../myModel"
|
|
5
5
|
import sql from "sql-template-strings"
|
|
6
6
|
import { table } from "console"
|
|
7
|
+
function keepOnlyDigits(str: string): number {
|
|
8
|
+
return Number(str.replace(/\D/g, ""))
|
|
9
|
+
}
|
|
7
10
|
export default class MyDBMigrator {
|
|
8
11
|
MyDB: ModelGenerator
|
|
9
12
|
onetimeLoadColumnContent: {
|
|
@@ -13,6 +16,7 @@ export default class MyDBMigrator {
|
|
|
13
16
|
COLUMN_DEFAULT: string
|
|
14
17
|
COLUMN_KEY: string
|
|
15
18
|
COLUMN_TYPE: string
|
|
19
|
+
CHARACTER_MAXIMUM_LENGTH: number | null
|
|
16
20
|
}[]
|
|
17
21
|
foreignKeyStatementList: string[]
|
|
18
22
|
|
|
@@ -240,6 +244,9 @@ export default class MyDBMigrator {
|
|
|
240
244
|
false
|
|
241
245
|
)) as any
|
|
242
246
|
}
|
|
247
|
+
// const temp = this.onetimeLoadColumnContent.forEach((row)=>{
|
|
248
|
+
// if(row.COLUMN_TYPE === '')
|
|
249
|
+
// })
|
|
243
250
|
}
|
|
244
251
|
|
|
245
252
|
private async checkIsColumnDataTypeChange(
|
|
@@ -257,17 +264,22 @@ export default class MyDBMigrator {
|
|
|
257
264
|
|
|
258
265
|
if (temp.length > 0) {
|
|
259
266
|
if (temp[0].DATA_TYPE !== dataType) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
+
if (temp[0].DATA_TYPE.search("varchar") >= 0) {
|
|
268
|
+
if (
|
|
269
|
+
temp[0].CHARACTER_MAXIMUM_LENGTH !==
|
|
270
|
+
keepOnlyDigits(temp[0].DATA_TYPE)
|
|
271
|
+
)
|
|
272
|
+
return true
|
|
273
|
+
} else {
|
|
274
|
+
console.log(
|
|
275
|
+
chalk.green`DATA_TYPE -> ${temp[0].DATA_TYPE} change to ${dataType}`
|
|
276
|
+
)
|
|
277
|
+
return true
|
|
278
|
+
}
|
|
267
279
|
}
|
|
268
280
|
if (temp[0].COLUMN_DEFAULT !== columnDefault) {
|
|
269
281
|
console.log(
|
|
270
|
-
chalk.green
|
|
282
|
+
chalk.green`COLUMN_DEFAULT -> ${temp[0].COLUMN_DEFAULT} change to ${columnDefault}`
|
|
271
283
|
)
|
|
272
284
|
return true
|
|
273
285
|
}
|