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