dbtasker 1.0.0 → 2.5.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 +521 -0
- package/columnop.js +748 -0
- package/dbop.js +236 -0
- package/enginesupport.js +237 -0
- package/function.js +927 -157
- package/index.js +117 -69
- package/package.json +15 -5
- package/tables.js +0 -1
- package/validation.js +1329 -0
- package/app.js +0 -32
- package/backup-tableoperation.js +0 -717
- package/check.js +0 -18
- package/checker.js +0 -359
- package/tableOperations.js +0 -614
- package/user_tables.js +0 -1655
package/index.js
CHANGED
|
@@ -1,99 +1,147 @@
|
|
|
1
1
|
const fncs = require("./function");
|
|
2
2
|
const recordedjson = require("./tables");
|
|
3
3
|
const cstyler = require("cstyler");
|
|
4
|
-
const checker = require("./
|
|
4
|
+
const checker = require("./validation");
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
const moduleName = "
|
|
9
|
+
const moduleName = "dbtasker";
|
|
10
|
+
const truers = [true, 1, "1", "true", "True", "TRUE"];
|
|
10
11
|
|
|
11
|
-
async function
|
|
12
|
+
module.exports = async function(allconfig, table_json) {
|
|
12
13
|
try {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (ifmysqldatabase === false) {
|
|
19
|
-
console.error("My SQL database is required to run ", moduleName, " module. Please install mysql2 to use this module. To install run this code on the terminal > npm install mysql2");
|
|
14
|
+
console.log(cstyler.blue("Initializing DBTASKER..."))
|
|
15
|
+
// check if enough database available on table json
|
|
16
|
+
const databaseNames = Object.keys(table_json);
|
|
17
|
+
if (databaseNames.length === 0) {
|
|
18
|
+
console.error(cstyler.bold("No data in table information object. Please add some database and tables."));
|
|
20
19
|
return;
|
|
21
20
|
}
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
} else {
|
|
29
|
-
console.error("Please provice a valid json file to continue.");
|
|
21
|
+
// Check config
|
|
22
|
+
console.log("Lets check config");
|
|
23
|
+
const isvalidconfig = fncs.isValidMySQLConfig(allconfig);
|
|
24
|
+
if (isvalidconfig === false) {
|
|
25
|
+
console.error("Please check your config object. It may requires more information...");
|
|
30
26
|
return;
|
|
31
27
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
28
|
+
const config = {
|
|
29
|
+
'host': allconfig.host,
|
|
30
|
+
'user': allconfig.user,
|
|
31
|
+
'password': allconfig.password,
|
|
32
|
+
'port': allconfig.port
|
|
33
|
+
}
|
|
34
|
+
// get don't touch database
|
|
35
|
+
let donttouchdb = [];
|
|
36
|
+
const donttouchkeys = ['donttouch', 'donottouch', 'donttouchdb', 'donottouchdb', 'donttouchdatabase', 'donottouchdatabase', 'dontdelete', 'donotdelete', 'dontdeletedb', 'donotdeletedb', 'dontdeletedatabase', 'donotdeletedatabase', 'dont_touch', 'do_not_touch', 'dont_touch_db', 'do_not_touch_db', 'dont_touch_database', 'do_not_touch_database', 'dont_delete', 'do_not_delete', 'dont_delete_db', 'do_not_delete_db', 'dont_delete_database', 'do_not_delete_database', 'reserveddb', 'reserved_db'];
|
|
37
|
+
for (const item of Object.keys(allconfig)) {
|
|
38
|
+
if (donttouchkeys.includes(item.toLowerCase())) {
|
|
39
|
+
if (Array.isArray(allconfig[item])) {
|
|
40
|
+
for (const dbs of allconfig[item]) {
|
|
41
|
+
if (typeof dbs !== "string") {
|
|
42
|
+
console.error("Non deletable database names must be string. Please provide valid data type.");
|
|
43
|
+
return;
|
|
48
44
|
}
|
|
49
|
-
} else if (ifexist === true) {
|
|
50
|
-
console.log(`${cstyler.purpal('Database name:')} ${cstyler.blue(dbName)} ${cstyler.green('is available')}`);
|
|
51
|
-
} else {
|
|
52
|
-
throw new Error("Can not perform. There is a database connection problem.");
|
|
53
45
|
}
|
|
46
|
+
donttouchdb = allconfig[item];
|
|
54
47
|
} else {
|
|
55
|
-
|
|
48
|
+
console.error(cstyler.bold("Please provide database name as an array that can not be deleted."));
|
|
49
|
+
return;
|
|
56
50
|
}
|
|
57
51
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
}
|
|
53
|
+
// Declare seperator
|
|
54
|
+
let seperator = "_";
|
|
55
|
+
const sepkeys = ['sep', 'seperator'];
|
|
56
|
+
for (const item of Object.keys(allconfig)) {
|
|
57
|
+
if (sepkeys.includes(item.toLowerCase())) {
|
|
58
|
+
seperator = allconfig[item];
|
|
59
|
+
break;
|
|
62
60
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
}
|
|
62
|
+
if (!fncs.isValidMySQLIdentifier(seperator)) {
|
|
63
|
+
seperator = "_";
|
|
64
|
+
}
|
|
65
|
+
let dropdatabase;
|
|
66
|
+
const dropdbkeys = ['dropdb', 'dropdatabase', 'deletedb', 'deletedatabase', 'drop_db', 'drop_database', 'delete_db', 'delete_database', 'removedb', 'removedatabase', 'remove_db', 'remove_database'];
|
|
67
|
+
for (const item of Object.keys(allconfig)) {
|
|
68
|
+
if (dropdbkeys.includes(item.toLowerCase())) {
|
|
69
|
+
dropdatabase = allconfig[item];
|
|
72
70
|
}
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
}
|
|
72
|
+
if (truers.includes(dropdatabase)) {
|
|
73
|
+
dropdatabase = true;
|
|
74
|
+
} else {
|
|
75
|
+
dropdatabase = false;
|
|
76
|
+
}
|
|
77
|
+
let droptable;
|
|
78
|
+
const droptablekeys = ['droptable', 'deletetable', 'drop_table', 'delete_table', 'removetable', 'remove_table', 'dropdbtable', 'deletedbtable', 'removedbtable', 'dropdatabasetable', 'deletedatabasetable', 'removedatabasetable', 'drop_db_table', 'delete_db_table', 'remove_db_table', 'drop_database_table', 'delete_database_table', 'remove_database_table'];
|
|
79
|
+
for (const item of Object.keys(allconfig)) {
|
|
80
|
+
if (droptablekeys.includes(item.toLowerCase())) {
|
|
81
|
+
droptable = allconfig[item];
|
|
75
82
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
}
|
|
84
|
+
if (truers.includes(droptable)) {
|
|
85
|
+
droptable = true;
|
|
86
|
+
} else {
|
|
87
|
+
droptable = false;
|
|
88
|
+
}
|
|
89
|
+
let dropcolumn;
|
|
90
|
+
const dropcolkeys = ['dropcol', 'dropcolumn', 'deletecol', 'deletecolumn', 'removecol', 'removecolumn', 'drop_col', 'drop_column', 'delete_col', 'delete_column', 'remove_col', 'remove_column'];
|
|
91
|
+
for (const item of Object.keys(allconfig)) {
|
|
92
|
+
if (dropcolkeys.includes(item.toLowerCase())) {
|
|
93
|
+
dropcolumn = allconfig[item];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (truers.includes(dropcolumn)) {
|
|
97
|
+
dropcolumn = true;
|
|
98
|
+
} else {
|
|
99
|
+
dropcolumn = false;
|
|
100
|
+
}
|
|
101
|
+
// lets check database type
|
|
102
|
+
const ifmysqldatabase = await fncs.isMySQLDatabase(config);
|
|
103
|
+
if (ifmysqldatabase === false) {
|
|
104
|
+
console.error("My SQL database is required to run ", moduleName, " module. Please install mysql2 to use this module. To install run this code on the terminal > npm install mysql2");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const isvalidmysqlversion = await fncs.isMySQL578OrAbove(config);
|
|
108
|
+
if (isvalidmysqlversion === false) {
|
|
109
|
+
console.error("My SQL version 5.7.8 or above is required. Please check if you have installed mysql2. To install: npm install mysql2");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
console.log(cstyler.bold.underline.yellow("Lets check if the table need an upgrade"))
|
|
113
|
+
// lets check all table name and column name
|
|
114
|
+
const checking = await checker.JSONchecker(table_json, config, seperator);
|
|
115
|
+
if (checking.status === false) {
|
|
116
|
+
console.log(cstyler.bold.underline.red("Please correct those information and try again."))
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const jsondata = checking.data;
|
|
120
|
+
console.log(cstyler.bold.purple("Lets start operation on databases."));
|
|
121
|
+
const dbop = require("./dbop");
|
|
122
|
+
const databaseop = await dbop.databaseAddDeleteAlter(config, jsondata, dropdatabase, donttouchdb, seperator);
|
|
123
|
+
if (databaseop === null) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
// Drop tables
|
|
127
|
+
if (droptable) {
|
|
128
|
+
console.log(cstyler.bold.purple("Lets drop unlisted table if needed."));
|
|
129
|
+
const droptableifneeded = await dbop.dropTable(config, jsondata, seperator);
|
|
130
|
+
if (droptableifneeded === null) {
|
|
80
131
|
return;
|
|
81
132
|
}
|
|
82
|
-
// table json file checking done
|
|
83
|
-
//
|
|
84
133
|
}
|
|
134
|
+
|
|
135
|
+
console.log(cstyler.bold.purple("Lets start working on columns"));
|
|
136
|
+
const colop = require("./columnop");
|
|
137
|
+
const columnop = await colop.columnAddDeleteAlter(config, jsondata, dropcolumn, seperator);
|
|
138
|
+
if (columnop === null) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
console.log(cstyler.bold.underline.green("<<<All database work is done perfectly>>>"));
|
|
85
142
|
} catch (err) {
|
|
86
143
|
console.error(err.message);
|
|
87
144
|
return;
|
|
88
145
|
}
|
|
89
146
|
}
|
|
90
147
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const { DBInfo } = require("./app");
|
|
98
|
-
const tables = require("./user_tables");
|
|
99
|
-
runit(DBInfo, tables);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbtasker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "You can create database and table on your own with a lot of functionality.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Md Nasiruddin Ahmed",
|
|
@@ -14,13 +14,23 @@
|
|
|
14
14
|
"mysql2",
|
|
15
15
|
"alter",
|
|
16
16
|
"modify",
|
|
17
|
-
""
|
|
17
|
+
"mysql2"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"cstyler": "^
|
|
24
|
-
"
|
|
25
|
-
|
|
23
|
+
"cstyler": "^3.0.0",
|
|
24
|
+
"fs": "^0.0.1-security",
|
|
25
|
+
"mysql2": "^3.14.3",
|
|
26
|
+
"path": "^0.12.7"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/kormoi/dbtasker"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/kormoi/dbtasker/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/kormoi/dbtasker#readme"
|
|
26
36
|
}
|
package/tables.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {}
|