gg-mysql-connector 1.0.99 → 1.0.103
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.
- package/app_INF.ts +5 -0
- package/app_model_const.ts +5 -1
- package/dist/app_INF.d.ts +6 -0
- package/dist/app_model_const.d.ts +6 -0
- package/dist/app_model_const.js +5 -0
- package/dist/src/MyDBMigrator/MyDBMigrator.d.ts +1 -0
- package/dist/src/MyDBMigrator/MyDBMigrator.js +31 -37
- package/package.json +1 -1
- package/src/MyDBMigrator/MyDBMigrator.ts +48 -59
package/app_INF.ts
CHANGED
package/app_model_const.ts
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
price: "number",
|
|
6
6
|
description: "string",
|
|
7
7
|
amount: "number",
|
|
8
|
-
userId: "number", },
|
|
8
|
+
userId: "number", }, item__stock : {
|
|
9
|
+
id: "number",
|
|
10
|
+
userId: "number",
|
|
11
|
+
itemId: "number",
|
|
12
|
+
amount: "number", }, user : {
|
|
9
13
|
id: "number",
|
|
10
14
|
name: "string", }, item__each_user : {
|
|
11
15
|
id: "number",
|
package/dist/app_INF.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export declare const app_model_const: {
|
|
|
7
7
|
readonly amount: "number";
|
|
8
8
|
readonly userId: "number";
|
|
9
9
|
};
|
|
10
|
+
readonly item__stock: {
|
|
11
|
+
readonly id: "number";
|
|
12
|
+
readonly userId: "number";
|
|
13
|
+
readonly itemId: "number";
|
|
14
|
+
readonly amount: "number";
|
|
15
|
+
};
|
|
10
16
|
readonly user: {
|
|
11
17
|
readonly id: "number";
|
|
12
18
|
readonly name: "string";
|
package/dist/app_model_const.js
CHANGED
|
@@ -26,6 +26,7 @@ export default class MyDBMigrator {
|
|
|
26
26
|
private checkIsColumnDataTypeChange;
|
|
27
27
|
private alterUniqueKey;
|
|
28
28
|
private alterIndex;
|
|
29
|
+
private deleteOldIndexVersion;
|
|
29
30
|
private alterPossibleEnum;
|
|
30
31
|
migrateView_v2(viewModel: MyViewModel[]): Promise<void>;
|
|
31
32
|
private checkIsPrimaryKey;
|
|
@@ -26,6 +26,8 @@ class MyDBMigrator {
|
|
|
26
26
|
await this.alterDataType(row.tableName, col);
|
|
27
27
|
await this.alterUniqueKey(row.tableName, col.COLUMN_NAME, col.IS_UNIQUE);
|
|
28
28
|
await this.alterIndex(row.tableName, col.COLUMN_NAME, col.IS_INDEX);
|
|
29
|
+
//!! delete this next version. need to execute only 1 time on production
|
|
30
|
+
await this.deleteOldIndexVersion(row.tableName, col.COLUMN_NAME);
|
|
29
31
|
await this.alterPossibleEnum(row.tableName, col.COLUMN_NAME, col.POSSIBLE_VALUE, col.IS_NOT_NULL);
|
|
30
32
|
await this.alterForeignKey(row.tableName, col);
|
|
31
33
|
}
|
|
@@ -170,49 +172,41 @@ class MyDBMigrator {
|
|
|
170
172
|
async alterUniqueKey(tableName, columnName, IS_UNIQUE) {
|
|
171
173
|
console.log("alterUniqueKey()");
|
|
172
174
|
const isUnique = Boolean(IS_UNIQUE);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
const uniqueIndexName = `${columnName}_unique`;
|
|
176
|
+
const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
|
|
177
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === uniqueIndexName)
|
|
178
|
+
? true
|
|
179
|
+
: false;
|
|
180
|
+
if (isUnique === true && isFound === false) {
|
|
181
|
+
await this.MyDB.query(`ALTER TABLE ${tableName} ADD CONSTRAINT ${uniqueIndexName} UNIQUE (${columnName});`);
|
|
178
182
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
(data.COLUMN_KEY !== "UNI" && isUnique === true)) {
|
|
183
|
-
const uniqueIndexName = `${columnName}_unique`;
|
|
184
|
-
const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
|
|
185
|
-
const isFound = indexList.find((iRow) => iRow.Key_name === uniqueIndexName)
|
|
186
|
-
? true
|
|
187
|
-
: false;
|
|
188
|
-
if (isUnique === true && isFound === false) {
|
|
189
|
-
await this.MyDB.query(`ALTER TABLE ${tableName} ADD CONSTRAINT ${uniqueIndexName} UNIQUE (${columnName});`);
|
|
190
|
-
}
|
|
191
|
-
else if (isUnique === false && isFound === true) {
|
|
192
|
-
//! DROP INDEX ถูกแล้ว อย่าแก้เป็น UNIQUE
|
|
193
|
-
await this.MyDB.query(`ALTER TABLE ${tableName} DROP INDEX ${uniqueIndexName};`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
183
|
+
else if (isUnique === false && isFound === true) {
|
|
184
|
+
//! DROP INDEX ถูกแล้ว อย่าแก้เป็น UNIQUE
|
|
185
|
+
await this.MyDB.query(`ALTER TABLE ${tableName} DROP INDEX ${uniqueIndexName};`);
|
|
196
186
|
}
|
|
197
187
|
}
|
|
198
188
|
async alterIndex(tableName, columnName, IS_INDEX) {
|
|
199
189
|
console.log("alterIndex()");
|
|
200
190
|
const isIndex = Boolean(IS_INDEX);
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
191
|
+
const indexIndexName = `${columnName}_index`;
|
|
192
|
+
const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
|
|
193
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
|
|
194
|
+
? true
|
|
195
|
+
: false;
|
|
196
|
+
if (isIndex === true && isFound === false)
|
|
197
|
+
await this.MyDB.query(`ALTER TABLE ${tableName} ADD INDEX ${indexIndexName} (${columnName});`);
|
|
198
|
+
else if (isIndex === false && isFound === true)
|
|
199
|
+
await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`);
|
|
200
|
+
}
|
|
201
|
+
async deleteOldIndexVersion(tableName, columnName) {
|
|
202
|
+
console.log("deleteOldIndexVersion()");
|
|
203
|
+
const indexIndexName = `${columnName}`;
|
|
204
|
+
const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
|
|
205
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
|
|
206
|
+
? true
|
|
207
|
+
: false;
|
|
208
|
+
if (isFound === true)
|
|
209
|
+
await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`);
|
|
216
210
|
}
|
|
217
211
|
async alterPossibleEnum(tableName, columnName, possibleValue, isNotNull) {
|
|
218
212
|
console.log("alterPossibleEnum()");
|
package/package.json
CHANGED
|
@@ -41,6 +41,9 @@ export default class MyDBMigrator {
|
|
|
41
41
|
await this.alterDataType(row.tableName, col)
|
|
42
42
|
await this.alterUniqueKey(row.tableName, col.COLUMN_NAME, col.IS_UNIQUE)
|
|
43
43
|
await this.alterIndex(row.tableName, col.COLUMN_NAME, col.IS_INDEX)
|
|
44
|
+
//!! delete this next version. need to execute only 1 time on production
|
|
45
|
+
await this.deleteOldIndexVersion(row.tableName, col.COLUMN_NAME)
|
|
46
|
+
|
|
44
47
|
await this.alterPossibleEnum(
|
|
45
48
|
row.tableName,
|
|
46
49
|
col.COLUMN_NAME,
|
|
@@ -258,40 +261,22 @@ export default class MyDBMigrator {
|
|
|
258
261
|
) {
|
|
259
262
|
console.log("alterUniqueKey()")
|
|
260
263
|
const isUnique = Boolean(IS_UNIQUE)
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
`SHOW INDEX FROM ${tableName}`
|
|
278
|
-
)) as { Key_name: string }[]
|
|
279
|
-
const isFound = indexList.find(
|
|
280
|
-
(iRow) => iRow.Key_name === uniqueIndexName
|
|
281
|
-
)
|
|
282
|
-
? true
|
|
283
|
-
: false
|
|
284
|
-
if (isUnique === true && isFound === false) {
|
|
285
|
-
await this.MyDB.query(
|
|
286
|
-
`ALTER TABLE ${tableName} ADD CONSTRAINT ${uniqueIndexName} UNIQUE (${columnName});`
|
|
287
|
-
)
|
|
288
|
-
} else if (isUnique === false && isFound === true) {
|
|
289
|
-
//! DROP INDEX ถูกแล้ว อย่าแก้เป็น UNIQUE
|
|
290
|
-
await this.MyDB.query(
|
|
291
|
-
`ALTER TABLE ${tableName} DROP INDEX ${uniqueIndexName};`
|
|
292
|
-
)
|
|
293
|
-
}
|
|
294
|
-
}
|
|
264
|
+
const uniqueIndexName = `${columnName}_unique`
|
|
265
|
+
const indexList = (await this.MyDB.query(
|
|
266
|
+
`SHOW INDEX FROM ${tableName}`
|
|
267
|
+
)) as { Key_name: string }[]
|
|
268
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === uniqueIndexName)
|
|
269
|
+
? true
|
|
270
|
+
: false
|
|
271
|
+
if (isUnique === true && isFound === false) {
|
|
272
|
+
await this.MyDB.query(
|
|
273
|
+
`ALTER TABLE ${tableName} ADD CONSTRAINT ${uniqueIndexName} UNIQUE (${columnName});`
|
|
274
|
+
)
|
|
275
|
+
} else if (isUnique === false && isFound === true) {
|
|
276
|
+
//! DROP INDEX ถูกแล้ว อย่าแก้เป็น UNIQUE
|
|
277
|
+
await this.MyDB.query(
|
|
278
|
+
`ALTER TABLE ${tableName} DROP INDEX ${uniqueIndexName};`
|
|
279
|
+
)
|
|
295
280
|
}
|
|
296
281
|
}
|
|
297
282
|
|
|
@@ -302,31 +287,35 @@ export default class MyDBMigrator {
|
|
|
302
287
|
) {
|
|
303
288
|
console.log("alterIndex()")
|
|
304
289
|
const isIndex = Boolean(IS_INDEX)
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
290
|
+
|
|
291
|
+
const indexIndexName = `${columnName}_index`
|
|
292
|
+
const indexList = (await this.MyDB.query(
|
|
293
|
+
`SHOW INDEX FROM ${tableName}`
|
|
294
|
+
)) as { Key_name: string }[]
|
|
295
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
|
|
296
|
+
? true
|
|
297
|
+
: false
|
|
298
|
+
if (isIndex === true && isFound === false)
|
|
299
|
+
await this.MyDB.query(
|
|
300
|
+
`ALTER TABLE ${tableName} ADD INDEX ${indexIndexName} (${columnName});`
|
|
301
|
+
)
|
|
302
|
+
else if (isIndex === false && isFound === true)
|
|
303
|
+
await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private async deleteOldIndexVersion(tableName: string, columnName: string) {
|
|
307
|
+
console.log("deleteOldIndexVersion()")
|
|
308
|
+
|
|
309
|
+
const indexIndexName = `${columnName}`
|
|
310
|
+
const indexList = (await this.MyDB.query(
|
|
311
|
+
`SHOW INDEX FROM ${tableName}`
|
|
312
|
+
)) as { Key_name: string }[]
|
|
313
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
|
|
314
|
+
? true
|
|
315
|
+
: false
|
|
316
|
+
|
|
317
|
+
if (isFound === true)
|
|
318
|
+
await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`)
|
|
330
319
|
}
|
|
331
320
|
|
|
332
321
|
private async alterPossibleEnum(
|