gg-mysql-connector 1.0.99 → 1.0.102
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.
|
@@ -170,49 +170,31 @@ class MyDBMigrator {
|
|
|
170
170
|
async alterUniqueKey(tableName, columnName, IS_UNIQUE) {
|
|
171
171
|
console.log("alterUniqueKey()");
|
|
172
172
|
const isUnique = Boolean(IS_UNIQUE);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
173
|
+
const uniqueIndexName = `${columnName}_unique`;
|
|
174
|
+
const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
|
|
175
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === uniqueIndexName)
|
|
176
|
+
? true
|
|
177
|
+
: false;
|
|
178
|
+
if (isUnique === true && isFound === false) {
|
|
179
|
+
await this.MyDB.query(`ALTER TABLE ${tableName} ADD CONSTRAINT ${uniqueIndexName} UNIQUE (${columnName});`);
|
|
178
180
|
}
|
|
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
|
-
}
|
|
181
|
+
else if (isUnique === false && isFound === true) {
|
|
182
|
+
//! DROP INDEX ถูกแล้ว อย่าแก้เป็น UNIQUE
|
|
183
|
+
await this.MyDB.query(`ALTER TABLE ${tableName} DROP INDEX ${uniqueIndexName};`);
|
|
196
184
|
}
|
|
197
185
|
}
|
|
198
186
|
async alterIndex(tableName, columnName, IS_INDEX) {
|
|
199
187
|
console.log("alterIndex()");
|
|
200
188
|
const isIndex = Boolean(IS_INDEX);
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (isIndex === true && isFound === false)
|
|
211
|
-
await this.MyDB.query(`ALTER TABLE ${tableName} ADD INDEX ${indexIndexName} (${columnName});`);
|
|
212
|
-
else if (isIndex === false && isFound === true)
|
|
213
|
-
await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
189
|
+
const indexIndexName = `${columnName}_index`;
|
|
190
|
+
const indexList = (await this.MyDB.query(`SHOW INDEX FROM ${tableName}`));
|
|
191
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
|
|
192
|
+
? true
|
|
193
|
+
: false;
|
|
194
|
+
if (isIndex === true && isFound === false)
|
|
195
|
+
await this.MyDB.query(`ALTER TABLE ${tableName} ADD INDEX ${indexIndexName} (${columnName});`);
|
|
196
|
+
else if (isIndex === false && isFound === true)
|
|
197
|
+
await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`);
|
|
216
198
|
}
|
|
217
199
|
async alterPossibleEnum(tableName, columnName, possibleValue, isNotNull) {
|
|
218
200
|
console.log("alterPossibleEnum()");
|
package/package.json
CHANGED
|
@@ -258,40 +258,22 @@ export default class MyDBMigrator {
|
|
|
258
258
|
) {
|
|
259
259
|
console.log("alterUniqueKey()")
|
|
260
260
|
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
|
-
}
|
|
261
|
+
const uniqueIndexName = `${columnName}_unique`
|
|
262
|
+
const indexList = (await this.MyDB.query(
|
|
263
|
+
`SHOW INDEX FROM ${tableName}`
|
|
264
|
+
)) as { Key_name: string }[]
|
|
265
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === uniqueIndexName)
|
|
266
|
+
? true
|
|
267
|
+
: false
|
|
268
|
+
if (isUnique === true && isFound === false) {
|
|
269
|
+
await this.MyDB.query(
|
|
270
|
+
`ALTER TABLE ${tableName} ADD CONSTRAINT ${uniqueIndexName} UNIQUE (${columnName});`
|
|
271
|
+
)
|
|
272
|
+
} else if (isUnique === false && isFound === true) {
|
|
273
|
+
//! DROP INDEX ถูกแล้ว อย่าแก้เป็น UNIQUE
|
|
274
|
+
await this.MyDB.query(
|
|
275
|
+
`ALTER TABLE ${tableName} DROP INDEX ${uniqueIndexName};`
|
|
276
|
+
)
|
|
295
277
|
}
|
|
296
278
|
}
|
|
297
279
|
|
|
@@ -302,31 +284,20 @@ export default class MyDBMigrator {
|
|
|
302
284
|
) {
|
|
303
285
|
console.log("alterIndex()")
|
|
304
286
|
const isIndex = Boolean(IS_INDEX)
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
)
|
|
320
|
-
? true
|
|
321
|
-
: false
|
|
322
|
-
if (isIndex === true && isFound === false)
|
|
323
|
-
await this.MyDB.query(
|
|
324
|
-
`ALTER TABLE ${tableName} ADD INDEX ${indexIndexName} (${columnName});`
|
|
325
|
-
)
|
|
326
|
-
else if (isIndex === false && isFound === true)
|
|
327
|
-
await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`)
|
|
328
|
-
}
|
|
329
|
-
}
|
|
287
|
+
|
|
288
|
+
const indexIndexName = `${columnName}_index`
|
|
289
|
+
const indexList = (await this.MyDB.query(
|
|
290
|
+
`SHOW INDEX FROM ${tableName}`
|
|
291
|
+
)) as { Key_name: string }[]
|
|
292
|
+
const isFound = indexList.find((iRow) => iRow.Key_name === indexIndexName)
|
|
293
|
+
? true
|
|
294
|
+
: false
|
|
295
|
+
if (isIndex === true && isFound === false)
|
|
296
|
+
await this.MyDB.query(
|
|
297
|
+
`ALTER TABLE ${tableName} ADD INDEX ${indexIndexName} (${columnName});`
|
|
298
|
+
)
|
|
299
|
+
else if (isIndex === false && isFound === true)
|
|
300
|
+
await this.MyDB.query(`DROP INDEX ${indexIndexName} ON ${tableName};`)
|
|
330
301
|
}
|
|
331
302
|
|
|
332
303
|
private async alterPossibleEnum(
|