dbtasker 2.5.0 → 3.0.0
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/README.md +14 -1
- package/addcolumn.js +264 -0
- package/altercolumn.js +595 -0
- package/dbop.js +41 -51
- package/dropcolumn.js +174 -0
- package/function.js +567 -104
- package/index.js +98 -32
- package/package.json +1 -1
- package/tableop.js +273 -0
- package/validation.js +224 -159
- package/columnop.js +0 -748
- package/tables.js +0 -0
package/validation.js
CHANGED
|
@@ -204,7 +204,7 @@ function validateDefault(columnType, defaultValue, length_value, nullable = fals
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
|
|
207
|
-
async function JSONchecker(table_json, config,
|
|
207
|
+
async function JSONchecker(table_json, config, separator = "_") {
|
|
208
208
|
// lets check all table name and column name
|
|
209
209
|
let baddatabaseName = [];
|
|
210
210
|
let badTableNames = [];
|
|
@@ -250,9 +250,9 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
250
250
|
if (fncs.isJsonObject(table_json)) {
|
|
251
251
|
// lets loop databases
|
|
252
252
|
for (const databaseName of Object.keys(table_json)) {
|
|
253
|
-
if (fncs.perseDatabaseNameWithLoop(databaseName,
|
|
253
|
+
if (fncs.perseDatabaseNameWithLoop(databaseName, separator) === false) {
|
|
254
254
|
baddatabaseName.push(
|
|
255
|
-
`${cstyler.
|
|
255
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
256
256
|
`${cstyler.red('- database name is not valid.')}`
|
|
257
257
|
)
|
|
258
258
|
}
|
|
@@ -268,10 +268,10 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
if (fncs.isJsonObject(table_json[databaseName][tableName])) {
|
|
271
|
-
if (fncs.perseTableNameWithLoop(tableName,
|
|
271
|
+
if (fncs.perseTableNameWithLoop(tableName, separator) === false) {
|
|
272
272
|
badTableNames.push(
|
|
273
|
-
`${cstyler.
|
|
274
|
-
`${cstyler.
|
|
273
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
274
|
+
`${cstyler.blue('of table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
275
275
|
`${cstyler.red('- table name is not valid.')}`
|
|
276
276
|
);
|
|
277
277
|
}
|
|
@@ -313,7 +313,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
313
313
|
}
|
|
314
314
|
if (typeof columntype !== "string" && columntype !== undefined) {
|
|
315
315
|
columntype = null;
|
|
316
|
-
}
|
|
316
|
+
} else if (typeof columntype === "string") columntype = columntype.toUpperCase();
|
|
317
317
|
/**
|
|
318
318
|
* Length_Value
|
|
319
319
|
*/
|
|
@@ -348,34 +348,37 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
348
348
|
* INDEX
|
|
349
349
|
* Index
|
|
350
350
|
*/
|
|
351
|
-
let indexvalue = undefined;
|
|
352
351
|
const indexkey = ["index", 'indexkey', 'index_key', 'indexing'];
|
|
352
|
+
const indprimarykey = ['primarykey', 'primary_key', 'primary', 'isprimary', 'isprimarykey'];
|
|
353
|
+
const induniquekey = ['unique', 'isunique', 'isuniquekey', 'uniqueindex', 'uniquekey', 'unique_index', 'unique_key'];
|
|
354
|
+
const indfulltextkey = ['fulltext', 'fulltextindex', 'isfulltextkey', 'fulltextkey', 'fulltext_key', 'isfulltext'];
|
|
355
|
+
const indspacialkey = ['spatial', 'spatialindex', 'isspatialkey', 'spatialkey', 'spatial_key', 'isspatial'];
|
|
353
356
|
for (const item of Object.keys(deepColumn)) {
|
|
354
357
|
if (indexkey.includes(item.toLowerCase())) {
|
|
355
358
|
indexes = deepColumn[item];
|
|
356
359
|
break;
|
|
357
|
-
} else if (
|
|
360
|
+
} else if (indprimarykey.includes(item.toLowerCase())) {
|
|
358
361
|
if (truers.includes(deepColumn[item])) {
|
|
359
362
|
indexes = "PRIMARY KEY";
|
|
360
363
|
break;
|
|
361
364
|
} else {
|
|
362
365
|
indexes = undefined;
|
|
363
366
|
}
|
|
364
|
-
} else if (
|
|
367
|
+
} else if (induniquekey.includes(item.toLowerCase())) {
|
|
365
368
|
if (truers.includes(deepColumn[item])) {
|
|
366
369
|
indexes = "UNIQUE";
|
|
367
370
|
break;
|
|
368
371
|
} else {
|
|
369
372
|
indexes = undefined;
|
|
370
373
|
}
|
|
371
|
-
} else if (
|
|
374
|
+
} else if (indfulltextkey.includes(item.toLowerCase())) {
|
|
372
375
|
if (truers.includes(deepColumn[item])) {
|
|
373
376
|
indexes = "FULLTEXT";
|
|
374
377
|
break;
|
|
375
378
|
} else {
|
|
376
379
|
indexes = undefined;
|
|
377
380
|
}
|
|
378
|
-
} else if (
|
|
381
|
+
} else if (indspacialkey.includes(item.toLowerCase())) {
|
|
379
382
|
if (truers.includes(deepColumn[item])) {
|
|
380
383
|
indexes = "SPATIAL";
|
|
381
384
|
break;
|
|
@@ -402,6 +405,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
402
405
|
* Null
|
|
403
406
|
*/
|
|
404
407
|
const nullkeys = ['null', 'nulls', 'nullable', 'optional', 'isnulable', 'allownull', 'canbenull'];
|
|
408
|
+
const notnullkeys = ['notnull', 'not_null', 'nonnullable', 'notnullable', 'required', 'disallownull', 'non_nullable', 'not_nullable', 'disallow_null'];
|
|
405
409
|
for (const item of Object.keys(deepColumn)) {
|
|
406
410
|
if (nullkeys.includes(item.toLowerCase())) {
|
|
407
411
|
if (truers.includes(deepColumn[item])) {
|
|
@@ -414,7 +418,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
414
418
|
nulls = true;
|
|
415
419
|
break;
|
|
416
420
|
}
|
|
417
|
-
} else if (
|
|
421
|
+
} else if (notnullkeys.includes(item.toLowerCase())) {
|
|
418
422
|
if (truers.includes(deepColumn[item])) {
|
|
419
423
|
nulls = false;
|
|
420
424
|
break;
|
|
@@ -436,7 +440,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
436
440
|
} else {
|
|
437
441
|
// lets check bad null
|
|
438
442
|
badnulls.push(
|
|
439
|
-
`${cstyler.
|
|
443
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} > ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} > ${cstyler.blue('Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.yellow('NULL')} ${cstyler.red('- must be true or false')}`
|
|
440
444
|
);
|
|
441
445
|
}
|
|
442
446
|
/**
|
|
@@ -452,10 +456,10 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
452
456
|
/**
|
|
453
457
|
* UNSIGNED
|
|
454
458
|
*/
|
|
455
|
-
const
|
|
456
|
-
|
|
459
|
+
const unsignedkey = ['numericunsigned', 'numeric_unsigned', 'unsigned', 'isunsigned'];
|
|
460
|
+
const signedkey = ['numericsigned', 'numeric_signed', 'signed', 'issigned'];
|
|
457
461
|
for (const item of Object.keys(deepColumn)) {
|
|
458
|
-
if (
|
|
462
|
+
if (unsignedkey.includes(item.toLowerCase())) {
|
|
459
463
|
if (truers.includes(deepColumn[item])) {
|
|
460
464
|
unsigned = true;
|
|
461
465
|
break;
|
|
@@ -466,7 +470,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
466
470
|
unsigned = null;
|
|
467
471
|
break;
|
|
468
472
|
}
|
|
469
|
-
} else if (
|
|
473
|
+
} else if (signedkey.includes(item.toLowerCase())) {
|
|
470
474
|
if (truers.includes(deepColumn[item])) {
|
|
471
475
|
unsigned = false;
|
|
472
476
|
break;
|
|
@@ -528,9 +532,9 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
528
532
|
// lets check column names
|
|
529
533
|
if (!fncs.isValidColumnName(columnName.toLowerCase())) {
|
|
530
534
|
badColumnNames.push(
|
|
531
|
-
`${cstyler.
|
|
532
|
-
`${cstyler.
|
|
533
|
-
`${cstyler.
|
|
535
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
536
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
537
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
534
538
|
`${cstyler.red('- column name is not valid.')}`
|
|
535
539
|
);
|
|
536
540
|
}
|
|
@@ -538,9 +542,9 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
538
542
|
const allMySQLColumnTypes = Object.keys(mysqlTypeMetadata);
|
|
539
543
|
if (typeof columntype !== "string") {
|
|
540
544
|
badtype.push(
|
|
541
|
-
`${cstyler.
|
|
542
|
-
`${cstyler.
|
|
543
|
-
`${cstyler.
|
|
545
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
546
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
547
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
544
548
|
`${cstyler.red('- must have type.')}`
|
|
545
549
|
);
|
|
546
550
|
columntype = null;
|
|
@@ -548,20 +552,20 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
548
552
|
if (engine !== undefined) {
|
|
549
553
|
if (!eng.isColumnTypeAllowed(engine, columntype.toUpperCase())) {
|
|
550
554
|
badengine.push(
|
|
551
|
-
`${cstyler.
|
|
552
|
-
`${cstyler.
|
|
553
|
-
`${cstyler.
|
|
554
|
-
`${cstyler.
|
|
555
|
-
`${cstyler.
|
|
555
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
556
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
557
|
+
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
558
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
559
|
+
`${cstyler.blue('> Type:')} ${cstyler.hex("#00d9ffff")(columntype.toUpperCase())} ` +
|
|
556
560
|
`${cstyler.red('> type is not supported by engine.')}`
|
|
557
561
|
)
|
|
558
562
|
}
|
|
559
563
|
}
|
|
560
564
|
if (!allMySQLColumnTypes.includes(columntype.toUpperCase())) {
|
|
561
565
|
badtype.push(
|
|
562
|
-
`${cstyler.
|
|
563
|
-
`${cstyler.
|
|
564
|
-
`${cstyler.
|
|
566
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
567
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
568
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
565
569
|
`${cstyler.red('> type - must have valid column type.')}`
|
|
566
570
|
);
|
|
567
571
|
columntype = null;
|
|
@@ -573,7 +577,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
573
577
|
// Check if length is required but missing
|
|
574
578
|
if (typeInfo.required && length_value === undefined) {
|
|
575
579
|
badlength.push(
|
|
576
|
-
`${cstyler.
|
|
580
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red('requires length but none provided.')}`
|
|
577
581
|
);
|
|
578
582
|
} else if (length_value !== undefined) {
|
|
579
583
|
let lenVals = length_value;
|
|
@@ -583,14 +587,14 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
583
587
|
if (typeInfo.lengthType === "int") {
|
|
584
588
|
if (!Number.isInteger(lenVals)) {
|
|
585
589
|
badlength.push(
|
|
586
|
-
`${cstyler.
|
|
590
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red('should have a valid integer length')}`
|
|
587
591
|
);
|
|
588
592
|
}
|
|
589
593
|
} else if (typeInfo.lengthType === "two-int") {
|
|
590
594
|
const parsed = parseQuotedListSafely(lenVals);
|
|
591
595
|
if (parsed.length !== 2) {
|
|
592
596
|
badlength.push(
|
|
593
|
-
`${cstyler.
|
|
597
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red('should have two integer values [precision, scale]')}`
|
|
594
598
|
);
|
|
595
599
|
} else {
|
|
596
600
|
const [precision, scale] = parsed;
|
|
@@ -599,7 +603,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
599
603
|
!Number.isInteger(scale) || scale < 0 || scale > precision
|
|
600
604
|
) {
|
|
601
605
|
badlength.push(
|
|
602
|
-
`${cstyler.
|
|
606
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red('has invalid precision or scale')}`
|
|
603
607
|
);
|
|
604
608
|
}
|
|
605
609
|
}
|
|
@@ -607,7 +611,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
607
611
|
const parsed = parseQuotedListSafely(lenVals);
|
|
608
612
|
if (parsed.length === 0) {
|
|
609
613
|
badlength.push(
|
|
610
|
-
`${cstyler.
|
|
614
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red('should have a valid list of options')}`
|
|
611
615
|
);
|
|
612
616
|
}
|
|
613
617
|
}
|
|
@@ -618,9 +622,9 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
618
622
|
if (typeof indexes === "string") {
|
|
619
623
|
if (typeInfo.dataType !== "numeric" || !['PRIMARY KEY', 'UNIQUE'].includes(indexes) || nulls === true || defaults !== undefined) {
|
|
620
624
|
badautoincrement.push(
|
|
621
|
-
`${cstyler.
|
|
622
|
-
`${cstyler.
|
|
623
|
-
`${cstyler.
|
|
625
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
626
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
627
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
624
628
|
`${cstyler.red('column must be')} ${cstyler.yellow('integer')} ${cstyler.red('type, should be')} ${cstyler.yellow('primary key')} ${cstyler.red('or')} ${cstyler.yellow('unique indexed')}, ` +
|
|
625
629
|
`${cstyler.red('should be')} ${cstyler.yellow('NOT NULL')}, ` +
|
|
626
630
|
`${cstyler.red('can not have a')} ${cstyler.yellow('DEFAULT')} ${cstyler.red('value.')}`
|
|
@@ -628,9 +632,9 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
628
632
|
}
|
|
629
633
|
} else {
|
|
630
634
|
badautoincrement.push(
|
|
631
|
-
`${cstyler.
|
|
632
|
-
`${cstyler.
|
|
633
|
-
`${cstyler.
|
|
635
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
636
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
637
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
634
638
|
`${cstyler.red('a valid')} ${cstyler.yellow('index')} ${cstyler.red('value must be ')}` +
|
|
635
639
|
`${cstyler.yellow('PRIMARY KEY, UNIQUE')} ${cstyler.red('for autoincrement.')}`
|
|
636
640
|
);
|
|
@@ -638,10 +642,10 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
638
642
|
if (engine !== undefined) {
|
|
639
643
|
if (!eng.isEngineFeatureAllowed(engine, 'AutoIncrement')) {
|
|
640
644
|
badengine.push(
|
|
641
|
-
`${cstyler.
|
|
642
|
-
`${cstyler.
|
|
643
|
-
`${cstyler.
|
|
644
|
-
`${cstyler.
|
|
645
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
646
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
647
|
+
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
648
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
645
649
|
`${cstyler.red('> Engine - does not support')}` +
|
|
646
650
|
`${cstyler.yellow(' - Autoincrement')}`
|
|
647
651
|
)
|
|
@@ -664,17 +668,17 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
664
668
|
}
|
|
665
669
|
if (autoincrementcolumnlist.length > 1) {
|
|
666
670
|
badautoincrement.push(
|
|
667
|
-
`${cstyler.
|
|
668
|
-
`${cstyler.
|
|
669
|
-
`${cstyler.
|
|
671
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
672
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
673
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
670
674
|
`${cstyler.red('- This table has more than one')} ${cstyler.yellow('auto increment')} ${cstyler.red('column. A table can have only one')} ${cstyler.yellow('auto increment')} ${cstyler.red('column.')}`
|
|
671
675
|
);
|
|
672
676
|
}
|
|
673
677
|
} else if (autoincrement === null) {
|
|
674
678
|
badautoincrement.push(
|
|
675
|
-
`${cstyler.
|
|
676
|
-
`${cstyler.
|
|
677
|
-
`${cstyler.
|
|
679
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
680
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
681
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
678
682
|
`${cstyler.red('- must true or false as valid autoincrement value')}`
|
|
679
683
|
);
|
|
680
684
|
}
|
|
@@ -733,9 +737,9 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
733
737
|
|
|
734
738
|
if (invalids.length) {
|
|
735
739
|
badcomment.push(
|
|
736
|
-
`${cstyler.
|
|
737
|
-
`${cstyler.
|
|
738
|
-
`${cstyler.
|
|
740
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
741
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
742
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
739
743
|
`${cstyler.red('- Invalid comment:')} ${invalids.join(cstyler.red(' | '))}`
|
|
740
744
|
);
|
|
741
745
|
}
|
|
@@ -753,10 +757,10 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
753
757
|
if (engine !== undefined) {
|
|
754
758
|
if (!eng.isEngineFeatureAllowed(engine, 'ZeroFill')) {
|
|
755
759
|
badengine.push(
|
|
756
|
-
`${cstyler.
|
|
757
|
-
`${cstyler.
|
|
758
|
-
`${cstyler.
|
|
759
|
-
`${cstyler.
|
|
760
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
761
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
762
|
+
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
763
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
760
764
|
`${cstyler.red('> Engine - does not support')}` +
|
|
761
765
|
`${cstyler.yellow(' - ZeroFill')}`
|
|
762
766
|
)
|
|
@@ -775,31 +779,31 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
775
779
|
if (typeof indexes === "string") {
|
|
776
780
|
if (columntype === "JSON") {
|
|
777
781
|
badindex.push(
|
|
778
|
-
`${cstyler.
|
|
779
|
-
`${cstyler.
|
|
780
|
-
`${cstyler.
|
|
782
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
783
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
784
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
781
785
|
`${cstyler.red('- is a JSON column which can not have an ')}${cstyler.yellow('index')} ${cstyler.red('property')}`
|
|
782
786
|
);
|
|
783
787
|
} else if (typeInfo.dataType !== "geometry" && indexes === "SPATIAL" || typeInfo.dataType === "geometry" && indexes !== "SPATIAL") {
|
|
784
788
|
badindex.push(
|
|
785
|
-
`${cstyler.
|
|
786
|
-
`${cstyler.
|
|
787
|
-
`${cstyler.
|
|
789
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
790
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
791
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
788
792
|
`${cstyler.red(' - ')}${cstyler.yellow('SPATIAL - index')} ${cstyler.red('can only be used with ')}${cstyler.yellow('GEOMETRY')} ${cstyler.red('data type and ')}${cstyler.yellow('GEOMETRY')} ${cstyler.red('can only be used with ')}${cstyler.yellow('SPATIAL - index')}`
|
|
789
793
|
);
|
|
790
794
|
} else if (indexes === "FULLTEXT" && typeInfo.dataType !== "string") {
|
|
791
795
|
badindex.push(
|
|
792
|
-
`${cstyler.
|
|
793
|
-
`${cstyler.
|
|
794
|
-
`${cstyler.
|
|
796
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
797
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
798
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
795
799
|
`${cstyler.red(' - ')}${cstyler.yellow('FULLTEXT - index')} ${cstyler.red('can only be used with ')}${cstyler.yellow('CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT')} ${cstyler.red('column types which are string.')}`
|
|
796
800
|
);
|
|
797
801
|
} else if (!validIndexValues.includes(indexes)) {
|
|
798
802
|
console.log(indexes);
|
|
799
803
|
badindex.push(
|
|
800
|
-
`${cstyler.
|
|
801
|
-
`${cstyler.
|
|
802
|
-
`${cstyler.
|
|
804
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
805
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
806
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
803
807
|
`${cstyler.red('- has unsupported index value.')} ` +
|
|
804
808
|
`${cstyler.red('Value must be')} ${cstyler.yellow(validIndexValues.join(', '))}`
|
|
805
809
|
);
|
|
@@ -808,10 +812,10 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
808
812
|
if (engine !== undefined) {
|
|
809
813
|
if (!eng.isEngineFeatureAllowed(engine, 'Index')) {
|
|
810
814
|
badengine.push(
|
|
811
|
-
`${cstyler.
|
|
812
|
-
`${cstyler.
|
|
813
|
-
`${cstyler.
|
|
814
|
-
`${cstyler.
|
|
815
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
816
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
817
|
+
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
818
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
815
819
|
`${cstyler.red('> Engine - does not support')}` +
|
|
816
820
|
`${cstyler.yellow(' - Index')}`
|
|
817
821
|
)
|
|
@@ -819,9 +823,9 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
819
823
|
}
|
|
820
824
|
} else {
|
|
821
825
|
badindex.push(
|
|
822
|
-
`${cstyler.
|
|
823
|
-
`${cstyler.
|
|
824
|
-
`${cstyler.
|
|
826
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
827
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
828
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
825
829
|
`${cstyler.red('- ')}${cstyler.yellow('index')} ${cstyler.red('value must be text or string.')}`
|
|
826
830
|
);
|
|
827
831
|
}
|
|
@@ -829,19 +833,23 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
829
833
|
let doubblePrimary = [];
|
|
830
834
|
for (const column of Object.keys(table_json[databaseName][tableName])) {
|
|
831
835
|
const doubleDeepColumn = table_json[databaseName][tableName][column];
|
|
832
|
-
for (const item of
|
|
833
|
-
if (
|
|
834
|
-
if (doubleDeepColumn[item].toUpperCase() === "
|
|
836
|
+
for (const item of Object.keys(doubleDeepColumn)) {
|
|
837
|
+
if (indexkey.includes(item.toLowerCase())) {
|
|
838
|
+
if (doubleDeepColumn[item].toUpperCase() === "PRIMARY KEY")
|
|
835
839
|
doubblePrimary.push(doubleDeepColumn[item]);
|
|
836
840
|
break;
|
|
841
|
+
} else if (indprimarykey.includes(item.toLowerCase())) {
|
|
842
|
+
if (truers.includes(doubleDeepColumn[item])) {
|
|
843
|
+
doubblePrimary.push(doubleDeepColumn[item]);
|
|
844
|
+
}
|
|
837
845
|
}
|
|
838
846
|
}
|
|
839
847
|
}
|
|
840
848
|
if (doubblePrimary.length > 1) {
|
|
841
849
|
badindex.push(
|
|
842
|
-
`${cstyler.
|
|
843
|
-
`${cstyler.
|
|
844
|
-
`${cstyler.
|
|
850
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
851
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
852
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
845
853
|
`${cstyler.red('- This table has more than one')} ${cstyler.yellow('PRIMARY KEY')} ${cstyler.red('column. A table can have only one')} ${cstyler.yellow('PRIMARY KEY')} ${cstyler.red('column.')}`
|
|
846
854
|
);
|
|
847
855
|
}
|
|
@@ -852,11 +860,11 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
852
860
|
contentObj[databaseName][tableName][columnName]._charset_ = _charset_;
|
|
853
861
|
} else if (!['text', 'string'].includes(typeInfo.dataType)) {
|
|
854
862
|
badcharacterset.push(
|
|
855
|
-
`${cstyler.
|
|
863
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.blue("> column type:")} ${cstyler.hex("#00d9ffff")(columntype)} ${cstyler.red('can not accept character set and must be a type that accept TEXT or STRING to set a')} ${cstyler.yellow("character set")}`
|
|
856
864
|
);
|
|
857
865
|
} else {
|
|
858
866
|
badcharacterset.push(
|
|
859
|
-
`${cstyler.
|
|
867
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.yellow("character set")} ${cstyler.red('value must have a valid value')}`
|
|
860
868
|
);
|
|
861
869
|
}
|
|
862
870
|
}
|
|
@@ -865,11 +873,11 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
865
873
|
contentObj[databaseName][tableName][columnName]._collate_ = _collate_;
|
|
866
874
|
} else if (!['text', 'string'].includes(typeInfo.dataType)) {
|
|
867
875
|
badcollation.push(
|
|
868
|
-
`${cstyler.
|
|
876
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.blue("> column type:")} ${cstyler.hex("#00d9ffff")(columntype)} ${cstyler.red('can not accept collate and must be a type that accept TEXT or STRING to set a')} ${cstyler.yellow("collate")}`
|
|
869
877
|
);
|
|
870
878
|
} else {
|
|
871
879
|
badcollation.push(
|
|
872
|
-
`${cstyler.
|
|
880
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.yellow("collate")} ${cstyler.red('value must have a valid value')}`
|
|
873
881
|
);
|
|
874
882
|
}
|
|
875
883
|
}
|
|
@@ -877,11 +885,11 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
877
885
|
const isvalid = await fncs.isCharsetCollationValid(config, contentObj[databaseName][tableName][columnName]._charset_, contentObj[databaseName][tableName][columnName]._collate_);
|
|
878
886
|
if (isvalid === false) {
|
|
879
887
|
badcarcol.push(
|
|
880
|
-
`${cstyler.
|
|
881
|
-
`${cstyler.
|
|
882
|
-
`${cstyler.
|
|
883
|
-
`${cstyler.
|
|
884
|
-
`${cstyler.
|
|
888
|
+
`${cstyler.blue("Database:")} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
889
|
+
`${cstyler.blue("Table:")} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
890
|
+
`${cstyler.blue("Column:")} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
891
|
+
`${cstyler.blue("> Character set:")} ${cstyler.hex("#00d9ffff")(contentObj[databaseName][tableName][columnName]._charset_)} ` +
|
|
892
|
+
`${cstyler.blue("> Collate:")} ${cstyler.hex("#00d9ffff")(contentObj[databaseName][tableName][columnName]._collate_)} ` +
|
|
885
893
|
`${cstyler.red("- is invalid combination")} `
|
|
886
894
|
)
|
|
887
895
|
}
|
|
@@ -891,9 +899,9 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
891
899
|
|
|
892
900
|
if (!result.valid) {
|
|
893
901
|
baddefaults.push(
|
|
894
|
-
`${cstyler.
|
|
895
|
-
`${cstyler.
|
|
896
|
-
`${cstyler.
|
|
902
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} > ` +
|
|
903
|
+
`${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} > ` +
|
|
904
|
+
`${cstyler.blue('Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red(result.message)}`
|
|
897
905
|
);
|
|
898
906
|
}
|
|
899
907
|
// lets check bad foreign_key delete and update options
|
|
@@ -902,7 +910,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
902
910
|
let fktable = undefined;
|
|
903
911
|
let fkcolumn = undefined;
|
|
904
912
|
let foreign_key = {};
|
|
905
|
-
const fk_variations = ["fk", "foreign_key", "foreignkey"];
|
|
913
|
+
const fk_variations = ["fk", "fuck", "foreign_key", "foreignkey"];
|
|
906
914
|
for (const item of Object.keys(deepColumn)) {
|
|
907
915
|
if (fk_variations.includes(item.toLowerCase())) {
|
|
908
916
|
foreign_key = deepColumn[item];
|
|
@@ -941,10 +949,10 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
941
949
|
}
|
|
942
950
|
if (!validFKSetOption.has(deleteOption)) {
|
|
943
951
|
badforeighkey.push(
|
|
944
|
-
`${cstyler.
|
|
945
|
-
`${cstyler.
|
|
946
|
-
`${cstyler.
|
|
947
|
-
`${cstyler.
|
|
952
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} > ` +
|
|
953
|
+
`${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} > ` +
|
|
954
|
+
`${cstyler.blue('Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
955
|
+
`${cstyler.hex("#00d9ffff")('foreign_key > delete')} ` +
|
|
948
956
|
`${cstyler.red('must be one of:')} ` +
|
|
949
957
|
`${cstyler.yellow('[true, "DELETE"] > work as > CASCADE, "CASCADE", [null, "NULL"] > work as > "SET NULL", "DEFAULT" > work as > "SET DEFAULT", "RESTRICT", "NO ACTION"')}, ` +
|
|
950
958
|
`${cstyler.red(". You can use lowercase too.")}`
|
|
@@ -953,20 +961,20 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
953
961
|
// If DELETE is null (SET NULL), column must allow NULLs
|
|
954
962
|
if ([null, "SET NULL", "NULL"].includes(deleteOption) && nulls !== true) {
|
|
955
963
|
badforeighkey.push(
|
|
956
|
-
`${cstyler.
|
|
957
|
-
`${cstyler.
|
|
958
|
-
`${cstyler.
|
|
959
|
-
`${cstyler.
|
|
964
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} > ` +
|
|
965
|
+
`${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} > ` +
|
|
966
|
+
`${cstyler.blue('Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
967
|
+
`${cstyler.hex("#00d9ffff")('foreign_key >')} ` +
|
|
960
968
|
`${cstyler.yellow('delete')} === ${cstyler.yellow('null')} - then column ${cstyler.red('NULL must be true')}`
|
|
961
969
|
);
|
|
962
970
|
}
|
|
963
971
|
// If DELETE is 'set default', column must have a DEFAULT value
|
|
964
972
|
else if (["DEFAULT", "SET DEFAULT"].includes(deleteOption) && defaults === undefined) {
|
|
965
973
|
badforeighkey.push(
|
|
966
|
-
`${cstyler.
|
|
967
|
-
`${cstyler.
|
|
968
|
-
`${cstyler.
|
|
969
|
-
`${cstyler.
|
|
974
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
975
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
976
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
977
|
+
`${cstyler.hex("#00d9ffff")('foreign_key >')} ${cstyler.red("delete === 'set default'")} - then column ${cstyler.red('DEFAULT must be defined')}`
|
|
970
978
|
);
|
|
971
979
|
}
|
|
972
980
|
}
|
|
@@ -975,10 +983,10 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
975
983
|
if (updateOption !== undefined) {
|
|
976
984
|
if (!validFKSetOption.has(updateOption)) {
|
|
977
985
|
badforeighkey.push(
|
|
978
|
-
`${cstyler.
|
|
979
|
-
`${cstyler.
|
|
980
|
-
`${cstyler.
|
|
981
|
-
`${cstyler.
|
|
986
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} > ` +
|
|
987
|
+
`${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} > ` +
|
|
988
|
+
`${cstyler.blue('Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
989
|
+
`${cstyler.hex("#00d9ffff")('foreign_key > ONUPDATE')} ` +
|
|
982
990
|
`${cstyler.red('must be one of:')} ` +
|
|
983
991
|
`${cstyler.yellow('[true, "DELETE"] > work as > CASCADE, "CASCADE", [null, "NULL"] > work as > "SET NULL", "DEFAULT" > work as > "SET DEFAULT", "RESTRICT", "NO ACTION"')}, ` +
|
|
984
992
|
`${cstyler.red(". You can use lowercase too.")}`
|
|
@@ -988,10 +996,10 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
988
996
|
// If ONUPDATE is null (SET NULL), column must allow NULLs
|
|
989
997
|
if ([null, "SET NULL", "NULL"].includes(updateOption) && nulls !== true) {
|
|
990
998
|
badforeighkey.push(
|
|
991
|
-
`${cstyler.
|
|
992
|
-
`${cstyler.
|
|
993
|
-
`${cstyler.
|
|
994
|
-
`${cstyler.
|
|
999
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} > ` +
|
|
1000
|
+
`${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} > ` +
|
|
1001
|
+
`${cstyler.blue('Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
1002
|
+
`${cstyler.hex("#00d9ffff")('foreign_key >')} ` +
|
|
995
1003
|
`${cstyler.yellow('update set to')} ${cstyler.yellow('null')} - then column ${cstyler.red('must be null true')}`
|
|
996
1004
|
);
|
|
997
1005
|
}
|
|
@@ -999,10 +1007,10 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
999
1007
|
// If DELETE is 'set default', column must have a DEFAULT value
|
|
1000
1008
|
else if (["DEFAULT", "SET DEFAULT"].includes(updateOption) && defaults === undefined) {
|
|
1001
1009
|
badforeighkey.push(
|
|
1002
|
-
`${cstyler.
|
|
1003
|
-
`${cstyler.
|
|
1004
|
-
`${cstyler.
|
|
1005
|
-
`${cstyler.
|
|
1010
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
1011
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1012
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
1013
|
+
`${cstyler.hex("#00d9ffff")('foreign_key >')} ${cstyler.red("update === 'set default'")} - then column ${cstyler.red('DEFAULT must be defined')}`
|
|
1006
1014
|
);
|
|
1007
1015
|
|
|
1008
1016
|
}
|
|
@@ -1030,21 +1038,78 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
1030
1038
|
if (table_json[databaseName].hasOwnProperty(fktable)) {
|
|
1031
1039
|
if (!table_json[databaseName][fktable].hasOwnProperty(fkcolumn)) {
|
|
1032
1040
|
badforeighkey.push(
|
|
1033
|
-
`${cstyler.
|
|
1034
|
-
`${cstyler.
|
|
1035
|
-
`${cstyler.
|
|
1036
|
-
`${cstyler.
|
|
1041
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
1042
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1043
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
1044
|
+
`${cstyler.blue('foreign_key > references > table > column -')} ${cstyler.yellow.underline(fkcolumn)} ${cstyler.red('do not exist')}`
|
|
1037
1045
|
);
|
|
1046
|
+
} else {
|
|
1047
|
+
const fkcolumndata = table_json[databaseName][fktable][fkcolumn];
|
|
1048
|
+
let coltype;
|
|
1049
|
+
let collength;
|
|
1050
|
+
let colunsigned;
|
|
1051
|
+
let colcarset;
|
|
1052
|
+
let colcollate;
|
|
1053
|
+
for (const item of Object.keys(fkcolumndata)) {
|
|
1054
|
+
if (coltypekeys.includes(item.toLowerCase())) {
|
|
1055
|
+
coltype = fkcolumndata[item];
|
|
1056
|
+
}
|
|
1057
|
+
if (legnthkeys.includes(item.toLowerCase())) {
|
|
1058
|
+
collength = fkcolumndata[item];
|
|
1059
|
+
}
|
|
1060
|
+
// get unsigned
|
|
1061
|
+
if (unsignedkey.includes(item.toLowerCase())) {
|
|
1062
|
+
if (truers.includes(fkcolumndata[item])) {
|
|
1063
|
+
colunsigned = true;
|
|
1064
|
+
} else if (falsers.includes(fkcolumndata[item])) {
|
|
1065
|
+
colunsigned = false;
|
|
1066
|
+
} else {
|
|
1067
|
+
colunsigned = null;
|
|
1068
|
+
}
|
|
1069
|
+
} else if (signedkey.includes(item.toLowerCase())) {
|
|
1070
|
+
if (truers.includes(fkcolumndata[item])) {
|
|
1071
|
+
colunsigned = false;
|
|
1072
|
+
} else if (falsers.includes(fkcolumndata[item])) {
|
|
1073
|
+
colunsigned = true;
|
|
1074
|
+
} else {
|
|
1075
|
+
colunsigned = null;
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
//get characterset and collate
|
|
1079
|
+
if (charactersetkeys.includes(item.toLowerCase())) {
|
|
1080
|
+
colcarset = fkcolumndata[item];
|
|
1081
|
+
}
|
|
1082
|
+
if (collationkeys.includes(item.toLowerCase())) {
|
|
1083
|
+
colcollate = fkcolumndata[item];
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
// lets check
|
|
1087
|
+
if (typeof coltype === "string") coltype = coltype.toUpperCase();
|
|
1088
|
+
if (coltype !== columntype) {
|
|
1089
|
+
badforeighkey.push(`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red(`> foreign_key > references >`)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(fktable)} ${cstyler.blue('Column:')} ${cstyler.hex("#00d9ffff")(fkcolumn)} - ${cstyler.red('- type need to match to be Foreign Key-capable')}`);
|
|
1090
|
+
}
|
|
1091
|
+
if (collength !== length_value) {
|
|
1092
|
+
badforeighkey.push(`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red(`> foreign_key > references >`)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(fktable)} ${cstyler.blue('Column:')} ${cstyler.hex("#00d9ffff")(fkcolumn)} - ${cstyler.red('- length value need to match to be Foreign Key-capable')}`);
|
|
1093
|
+
}
|
|
1094
|
+
if (colunsigned !== unsigned) {
|
|
1095
|
+
badforeighkey.push(`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red(`> foreign_key > references >`)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(fktable)} ${cstyler.blue('Column:')} ${cstyler.hex("#00d9ffff")(fkcolumn)} - ${cstyler.red('- unsigned value need to match to be Foreign Key-capable')}`);
|
|
1096
|
+
}
|
|
1097
|
+
if (colcarset !== _charset_) {
|
|
1098
|
+
badforeighkey.push(`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red(`> foreign_key > references >`)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(fktable)} ${cstyler.blue('Column:')} ${cstyler.hex("#00d9ffff")(fkcolumn)} - ${cstyler.red('- characterset value need to match to be Foreign Key-capable')}`);
|
|
1099
|
+
}
|
|
1100
|
+
if (colcollate !== _collate_) {
|
|
1101
|
+
badforeighkey.push(`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red(`> foreign_key > references >`)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(fktable)} ${cstyler.blue('Column:')} ${cstyler.hex("#00d9ffff")(fkcolumn)} - ${cstyler.red('- collation value need to match to be Foreign Key-capable')}`);
|
|
1102
|
+
}
|
|
1038
1103
|
}
|
|
1039
1104
|
} else {
|
|
1040
|
-
badforeighkey.push(`${cstyler.
|
|
1105
|
+
badforeighkey.push(`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(`${columnName} > foreign_key > references >`)} ${cstyler.blue('Table:')} ${cstyler.underline.yellow(fktable)} - ${cstyler.red('do not exist')}`)
|
|
1041
1106
|
}
|
|
1042
1107
|
} else {
|
|
1043
1108
|
badforeighkey.push(
|
|
1044
|
-
`${cstyler.
|
|
1045
|
-
`${cstyler.
|
|
1046
|
-
`${cstyler.
|
|
1047
|
-
`${cstyler.
|
|
1109
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
1110
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1111
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
1112
|
+
`${cstyler.hex("#00d9ffff")('foreign_key > references -')} ${cstyler.red('must have a table and column property referancing to referance table column')}`
|
|
1048
1113
|
);
|
|
1049
1114
|
}
|
|
1050
1115
|
|
|
@@ -1072,10 +1137,10 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
1072
1137
|
if (engine !== undefined) {
|
|
1073
1138
|
if (!eng.isEngineFeatureAllowed(engine, 'Null')) {
|
|
1074
1139
|
badengine.push(
|
|
1075
|
-
`${cstyler.
|
|
1076
|
-
`${cstyler.
|
|
1077
|
-
`${cstyler.
|
|
1078
|
-
`${cstyler.
|
|
1140
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
1141
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1142
|
+
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
1143
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
1079
1144
|
`${cstyler.red('> Engine - does not support')}` +
|
|
1080
1145
|
`${cstyler.yellow(' - Null')}`
|
|
1081
1146
|
)
|
|
@@ -1088,10 +1153,10 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
1088
1153
|
if (engine !== undefined) {
|
|
1089
1154
|
if (!eng.isEngineFeatureAllowed(engine, 'Default')) {
|
|
1090
1155
|
badengine.push(
|
|
1091
|
-
`${cstyler.
|
|
1092
|
-
`${cstyler.
|
|
1093
|
-
`${cstyler.
|
|
1094
|
-
`${cstyler.
|
|
1156
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
1157
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1158
|
+
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
1159
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
1095
1160
|
`${cstyler.red('> Engine - does not support')}` +
|
|
1096
1161
|
`${cstyler.yellow(' - Default')}`
|
|
1097
1162
|
)
|
|
@@ -1141,7 +1206,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
1141
1206
|
contentObj[databaseName][tableName]._charset_ = charvalue;
|
|
1142
1207
|
} else {
|
|
1143
1208
|
badcharacterset.push(
|
|
1144
|
-
`${cstyler.
|
|
1209
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> character set key:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red('must have a valid character set value')}`
|
|
1145
1210
|
);
|
|
1146
1211
|
}
|
|
1147
1212
|
} else if (collationkeys.includes(columnName.toLowerCase())) {
|
|
@@ -1150,7 +1215,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
1150
1215
|
contentObj[databaseName][tableName]._collate_ = colvalue;
|
|
1151
1216
|
} else {
|
|
1152
1217
|
badcollation.push(
|
|
1153
|
-
`${cstyler.
|
|
1218
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> collate key:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red('must have a valid collate value')}`
|
|
1154
1219
|
);
|
|
1155
1220
|
}
|
|
1156
1221
|
} else if (enginekey.includes(columnName.toLowerCase())) {
|
|
@@ -1160,38 +1225,38 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
1160
1225
|
contentObj[databaseName][tableName]._engine_ = engvalue;
|
|
1161
1226
|
} else {
|
|
1162
1227
|
badengine.push(
|
|
1163
|
-
`${cstyler.
|
|
1228
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Engine key:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.blue("Engine name: ")} ${cstyler.hex("#00d9ffff")(engvalue)} ${cstyler.red('- The storage engine exists in MySQL source code but is not available on this server.')}`
|
|
1164
1229
|
);
|
|
1165
1230
|
}
|
|
1166
1231
|
} else {
|
|
1167
1232
|
badengine.push(
|
|
1168
|
-
`${cstyler.
|
|
1233
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Engine key:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.blue("Engine name:")} ${cstyler.hex("#00d9ffff")(engvalue)} ${cstyler.red('- must have a valid engine value')}`
|
|
1169
1234
|
);
|
|
1170
1235
|
}
|
|
1171
1236
|
} else if (commetnkey.includes(columnName.toLowerCase())) {
|
|
1172
1237
|
const commentval = table_json[databaseName][tableName][columnName];
|
|
1173
1238
|
if (!validateMySQLComment(commentval).valid) {
|
|
1174
1239
|
badcomment.push(
|
|
1175
|
-
`${cstyler.
|
|
1176
|
-
`${cstyler.
|
|
1177
|
-
`${cstyler.
|
|
1240
|
+
`${cstyler.blue("Database:")} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
1241
|
+
`${cstyler.blue("> Table:")} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1242
|
+
`${cstyler.blue("> Table comment:")} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
1178
1243
|
`${cstyler.red("- Invalid comment:")} ` +
|
|
1179
1244
|
result.errors.map(e => cstyler.red(e)).join(", ")
|
|
1180
1245
|
)
|
|
1181
1246
|
}
|
|
1182
1247
|
} else {
|
|
1183
1248
|
badColumnNames.push(
|
|
1184
|
-
`${cstyler.
|
|
1249
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> columnName:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.red('- That column name have some problem with its value')}`
|
|
1185
1250
|
)
|
|
1186
1251
|
}
|
|
1187
1252
|
if (contentObj[databaseName][tableName].hasOwnProperty("_collate_") && contentObj[databaseName][tableName].hasOwnProperty("_charset_")) {
|
|
1188
1253
|
const isvalid = await fncs.isCharsetCollationValid(config, contentObj[databaseName][tableName]._charset_, contentObj[databaseName][tableName]._collate_);
|
|
1189
1254
|
if (isvalid === false) {
|
|
1190
1255
|
badcarcol.push(
|
|
1191
|
-
`${cstyler.
|
|
1192
|
-
`${cstyler.
|
|
1193
|
-
`${cstyler.
|
|
1194
|
-
`${cstyler.
|
|
1256
|
+
`${cstyler.blue("Database:")} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
1257
|
+
`${cstyler.blue("Table:")} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1258
|
+
`${cstyler.blue("> Character set:")} ${cstyler.hex("#00d9ffff")(contentObj[databaseName][tableName]._charset_)} ` +
|
|
1259
|
+
`${cstyler.blue("> Collate:")} ${cstyler.hex("#00d9ffff")(contentObj[databaseName][tableName]._collate_)} ` +
|
|
1195
1260
|
`${cstyler.red("- is invalid combination")} `
|
|
1196
1261
|
)
|
|
1197
1262
|
}
|
|
@@ -1205,7 +1270,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
1205
1270
|
contentObj[databaseName]._charset_ = charvalue;
|
|
1206
1271
|
} else {
|
|
1207
1272
|
badcharacterset.push(
|
|
1208
|
-
`${cstyler.
|
|
1273
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> character set key:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.red('must have a valid character set value')}`
|
|
1209
1274
|
);
|
|
1210
1275
|
}
|
|
1211
1276
|
} else if (collationkeys.includes(tableName.toLowerCase())) {
|
|
@@ -1214,7 +1279,7 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
1214
1279
|
contentObj[databaseName]._collate_ = colvalue;
|
|
1215
1280
|
} else {
|
|
1216
1281
|
badcollation.push(
|
|
1217
|
-
`${cstyler.
|
|
1282
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> collate key:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.red('must have a valid collate value')}`
|
|
1218
1283
|
);
|
|
1219
1284
|
}
|
|
1220
1285
|
} else if (commetnkey.includes(tableName.toLowerCase())) {
|
|
@@ -1223,24 +1288,24 @@ async function JSONchecker(table_json, config, seperator = "_") {
|
|
|
1223
1288
|
contentObj[databaseName]._comment_ = commentval;
|
|
1224
1289
|
} else {
|
|
1225
1290
|
badcomment.push(
|
|
1226
|
-
`${cstyler.
|
|
1227
|
-
`${cstyler.
|
|
1291
|
+
`${cstyler.blue("Database:")} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
1292
|
+
`${cstyler.blue("> Database comment:")} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1228
1293
|
`${cstyler.red("- Invalid comment:")} ` +
|
|
1229
1294
|
result.errors.map(e => cstyler.red(e)).join(", ")
|
|
1230
1295
|
)
|
|
1231
1296
|
}
|
|
1232
1297
|
} else {
|
|
1233
1298
|
badTableNames.push(
|
|
1234
|
-
`${cstyler.
|
|
1299
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.red('- That table may have some problem with its property')}`
|
|
1235
1300
|
)
|
|
1236
1301
|
}
|
|
1237
1302
|
if (contentObj[databaseName].hasOwnProperty("_collate_") && contentObj[databaseName].hasOwnProperty("_charset_")) {
|
|
1238
1303
|
const isvalid = await fncs.isCharsetCollationValid(config, contentObj[databaseName]._charset_, contentObj[databaseName]._collate_);
|
|
1239
1304
|
if (isvalid === false) {
|
|
1240
1305
|
badcarcol.push(
|
|
1241
|
-
`${cstyler.
|
|
1242
|
-
`${cstyler.
|
|
1243
|
-
`${cstyler.
|
|
1306
|
+
`${cstyler.blue("Database:")} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
1307
|
+
`${cstyler.blue("> Character set:")} ${cstyler.hex("#00d9ffff")(contentObj[databaseName]._charset_)} ` +
|
|
1308
|
+
`${cstyler.blue("> Collate:")} ${cstyler.hex("#00d9ffff")(contentObj[databaseName]._collate_)} ` +
|
|
1244
1309
|
`${cstyler.red("- is invalid combination")} `
|
|
1245
1310
|
)
|
|
1246
1311
|
}
|