dbtasker 3.0.1 → 3.0.3
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/index.js +1 -1
- package/package.json +2 -2
- package/validation.js +41 -38
package/index.js
CHANGED
|
@@ -143,7 +143,7 @@ module.exports = async function (allconfig, table_json) {
|
|
|
143
143
|
console.log(cstyler.bold.underline.yellow("Lets check if the table need an upgrade"))
|
|
144
144
|
// lets check all table name and column name
|
|
145
145
|
const checking = await checker.JSONchecker(table_json, config, separator);
|
|
146
|
-
if (checking
|
|
146
|
+
if (checking === false) {
|
|
147
147
|
console.log(cstyler.bold.underline.red("Please correct those information and try again."))
|
|
148
148
|
return;
|
|
149
149
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbtasker",
|
|
3
|
-
"version": "3.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.0.3",
|
|
4
|
+
"description": "dbtasker is a powerful and developer-friendly MySQL schema automation tool that converts JSON-based definitions into validated SQL that allows developers to declaratively define databases, tables, columns, indexes, and foreign keys using a flexible, case-insensitive JSON schema.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Md Nasiruddin Ahmed",
|
|
7
7
|
"type": "commonjs",
|
package/validation.js
CHANGED
|
@@ -527,7 +527,7 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
527
527
|
/**
|
|
528
528
|
* Getting variable is ended
|
|
529
529
|
*/
|
|
530
|
-
const typeInfo = mysqlTypeMetadata[columntype.toUpperCase()];
|
|
530
|
+
const typeInfo = mysqlTypeMetadata[fncs.stringifyAny(columntype).toUpperCase()];
|
|
531
531
|
|
|
532
532
|
// lets check column names
|
|
533
533
|
if (!fncs.isValidColumnName(columnName.toLowerCase())) {
|
|
@@ -557,7 +557,7 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
557
557
|
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
558
558
|
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
559
559
|
`${cstyler.blue('> Type:')} ${cstyler.hex("#00d9ffff")(columntype.toUpperCase())} ` +
|
|
560
|
-
`${cstyler.red('
|
|
560
|
+
`${cstyler.red('is not supported by')} ` + `${cstyler.yellow('Engine')}`
|
|
561
561
|
)
|
|
562
562
|
}
|
|
563
563
|
}
|
|
@@ -646,8 +646,8 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
646
646
|
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
647
647
|
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
648
648
|
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
649
|
-
`${cstyler.
|
|
650
|
-
`${cstyler.yellow('
|
|
649
|
+
`${cstyler.yellow("> Engine")} ${cstyler.red('does not support ')} ` +
|
|
650
|
+
`${cstyler.yellow('Autoincrement')}`
|
|
651
651
|
)
|
|
652
652
|
}
|
|
653
653
|
}
|
|
@@ -684,29 +684,29 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
684
684
|
}
|
|
685
685
|
// check unsigned
|
|
686
686
|
if (typeof unsigned === "boolean") {
|
|
687
|
-
//
|
|
687
|
+
// Invalid use of unsigned on a non-numeric type
|
|
688
688
|
if (typeInfo !== undefined) {
|
|
689
689
|
if (typeInfo.supportsUnsigned === false) {
|
|
690
690
|
badunsigned.push(
|
|
691
|
-
cstyler`{
|
|
692
|
-
cstyler`{
|
|
693
|
-
cstyler`{
|
|
691
|
+
cstyler`{blue Database:} {hex("#00d9ffff") ${databaseName}} ` +
|
|
692
|
+
cstyler`{blue > Table:} {hex("#00d9ffff") ${tableName}} ` +
|
|
693
|
+
cstyler`{blue > Column:} {hex("#00d9ffff") ${columnName}} ` +
|
|
694
694
|
`${cstyler.red(" - has `unsigned` but type ")} ${cstyler.yellow(columntype)} ${cstyler.red(" do not support signed or unsigned modifiers.")}`
|
|
695
695
|
);
|
|
696
696
|
}
|
|
697
697
|
} else {
|
|
698
698
|
badunsigned.push(
|
|
699
|
-
cstyler`{
|
|
700
|
-
cstyler`{
|
|
701
|
-
cstyler`{
|
|
699
|
+
cstyler`{blue Database:} {hex("#00d9ffff") ${databaseName}} ` +
|
|
700
|
+
cstyler`{blue > Table:} {hex("#00d9ffff") ${tableName}} ` +
|
|
701
|
+
cstyler`{blue > Column:} {hex("#00d9ffff") ${columnName}} ` +
|
|
702
702
|
cstyler.red(" - can not validate signed or unsigned modifier with invalid column type")
|
|
703
703
|
);
|
|
704
704
|
}
|
|
705
705
|
} else if (unsigned === null) {
|
|
706
706
|
badunsigned.push(
|
|
707
|
-
cstyler`{
|
|
708
|
-
cstyler`{
|
|
709
|
-
cstyler`{
|
|
707
|
+
cstyler`{blue Database:} {hex("#00d9ffff") ${databaseName}} ` +
|
|
708
|
+
cstyler`{blue > Table:} {hex("#00d9ffff") ${tableName}} ` +
|
|
709
|
+
cstyler`{blue > Column:} {hex("#00d9ffff") ${columnName}} ` +
|
|
710
710
|
cstyler.red(" - has invalid signed or unsigned value")
|
|
711
711
|
);
|
|
712
712
|
}
|
|
@@ -746,12 +746,12 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
746
746
|
}
|
|
747
747
|
// check zerofill
|
|
748
748
|
if (zerofill === true && typeInfo !== undefined) {
|
|
749
|
-
if (
|
|
749
|
+
if (typeInfo.dataType !== "numeric") {
|
|
750
750
|
badzerofill.push(
|
|
751
|
-
cstyler
|
|
752
|
-
cstyler
|
|
753
|
-
cstyler
|
|
754
|
-
cstyler.red(" - for `zerofill` column type has to be numeric")
|
|
751
|
+
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ff")(databaseName)} ` +
|
|
752
|
+
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ff")(tableName)} ` +
|
|
753
|
+
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ff")(columnName)} ` +
|
|
754
|
+
cstyler.red(" - for `") + cstyler.yellow('zerofill') + cstyler.red("` column type has to be numeric")
|
|
755
755
|
);
|
|
756
756
|
}
|
|
757
757
|
if (engine !== undefined) {
|
|
@@ -761,16 +761,16 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
761
761
|
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
762
762
|
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
763
763
|
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
764
|
-
`${cstyler.
|
|
765
|
-
`${cstyler.yellow('
|
|
764
|
+
`${cstyler.yellow("> Engine")} ${cstyler.red('does not support ')} ` +
|
|
765
|
+
`${cstyler.yellow('ZeroFill')}`
|
|
766
766
|
)
|
|
767
767
|
}
|
|
768
768
|
}
|
|
769
769
|
} else if (zerofill === null) {
|
|
770
770
|
badzerofill.push(
|
|
771
|
-
cstyler`{
|
|
772
|
-
cstyler`{
|
|
773
|
-
cstyler`{
|
|
771
|
+
cstyler`{blue Database:} {hex("#00d9ffff") ${databaseName}} ` +
|
|
772
|
+
cstyler`{blue > Table:} {hex("#00d9ffff") ${tableName}} ` +
|
|
773
|
+
cstyler`{blue > Column:} {hex("#00d9ffff") ${columnName}} ` +
|
|
774
774
|
cstyler.red(" - has invalid `zerofill` value and must be boolean or simillar")
|
|
775
775
|
);
|
|
776
776
|
}
|
|
@@ -816,8 +816,8 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
816
816
|
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
817
817
|
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
818
818
|
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
819
|
-
`${cstyler.
|
|
820
|
-
`${cstyler.yellow('
|
|
819
|
+
`${cstyler.yellow("> Engine")} ${cstyler.red(' does not support')} ` +
|
|
820
|
+
`${cstyler.yellow('Index')}`
|
|
821
821
|
)
|
|
822
822
|
}
|
|
823
823
|
}
|
|
@@ -1041,7 +1041,7 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
1041
1041
|
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
1042
1042
|
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1043
1043
|
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
1044
|
-
`${cstyler.blue('foreign_key
|
|
1044
|
+
`${cstyler.blue('foreign_key > table:')} ${fktable}, ${cstyler.blue(' > column:')} ${fkcolumn} ${cstyler.red('do not exist')}`
|
|
1045
1045
|
);
|
|
1046
1046
|
} else {
|
|
1047
1047
|
const fkcolumndata = table_json[databaseName][fktable][fkcolumn];
|
|
@@ -1086,30 +1086,30 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
1086
1086
|
// lets check
|
|
1087
1087
|
if (typeof coltype === "string") coltype = coltype.toUpperCase();
|
|
1088
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
|
|
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 >`)} ${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
1090
|
}
|
|
1091
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
|
|
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 >`)} ${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
1093
|
}
|
|
1094
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
|
|
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 >`)} ${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
1096
|
}
|
|
1097
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
|
|
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 >`)} ${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
1099
|
}
|
|
1100
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
|
|
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 >`)} ${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
1102
|
}
|
|
1103
1103
|
}
|
|
1104
1104
|
} else {
|
|
1105
|
-
badforeighkey.push(`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(
|
|
1105
|
+
badforeighkey.push(`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ${cstyler.blue("> foreign_key >")} ${cstyler.blue('Table:')} ${cstyler.underline.yellow(fktable)} - ${cstyler.red('do not exist')}`)
|
|
1106
1106
|
}
|
|
1107
1107
|
} else {
|
|
1108
1108
|
badforeighkey.push(
|
|
1109
1109
|
`${cstyler.blue('Database:')} ${cstyler.hex("#00d9ffff")(databaseName)} ` +
|
|
1110
1110
|
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1111
1111
|
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
1112
|
-
`${cstyler.
|
|
1112
|
+
`${cstyler.blue('> foreign_key > -')} ${cstyler.red('must have a')} ${cstyler.yellow('reference table')} ${cstyler.red('and')} ${cstyler.yellow('reference column')} ${cstyler.red('property referancing to referance table > column')}`
|
|
1113
1113
|
);
|
|
1114
1114
|
}
|
|
1115
1115
|
|
|
@@ -1141,8 +1141,8 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
1141
1141
|
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1142
1142
|
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
1143
1143
|
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
1144
|
-
`${cstyler.
|
|
1145
|
-
`${cstyler.yellow('
|
|
1144
|
+
`${cstyler.yellow("> Engine")} ${cstyler.red(' does not support')} ` +
|
|
1145
|
+
`${cstyler.yellow('Null')}`
|
|
1146
1146
|
)
|
|
1147
1147
|
}
|
|
1148
1148
|
}
|
|
@@ -1157,8 +1157,8 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
1157
1157
|
`${cstyler.blue('> Table:')} ${cstyler.hex("#00d9ffff")(tableName)} ` +
|
|
1158
1158
|
`${cstyler.blue('> Engine:')} ${cstyler.hex("#00d9ffff")(engine)} ` +
|
|
1159
1159
|
`${cstyler.blue('> Column:')} ${cstyler.hex("#00d9ffff")(columnName)} ` +
|
|
1160
|
-
`${cstyler.
|
|
1161
|
-
`${cstyler.yellow('
|
|
1160
|
+
`${cstyler.yellow("> Engine")} ${cstyler.red(' does not support')} ` +
|
|
1161
|
+
`${cstyler.yellow('Default')}`
|
|
1162
1162
|
)
|
|
1163
1163
|
}
|
|
1164
1164
|
}
|
|
@@ -1351,6 +1351,9 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
1351
1351
|
if (badunsigned.length > 0) {
|
|
1352
1352
|
console.error(`UNSIGNED values that are not correct: \n${badunsigned.join("\n")}`);
|
|
1353
1353
|
}
|
|
1354
|
+
if (badzerofill.length > 0) {
|
|
1355
|
+
console.error(`ZEROFILL values that are not correct: \n${badzerofill.join("\n")}`);
|
|
1356
|
+
}
|
|
1354
1357
|
if (badnulls.length > 0) {
|
|
1355
1358
|
console.error(`NULL values that are not correct: \n${badnulls.join("\n")}`);
|
|
1356
1359
|
}
|