dbtasker 1.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/app.js +32 -0
- package/backup-tableoperation.js +717 -0
- package/check.js +18 -0
- package/checker.js +359 -0
- package/function.js +673 -0
- package/index.js +99 -0
- package/package.json +26 -0
- package/tableOperations.js +614 -0
- package/tables.js +1 -0
- package/user_tables.js +1655 -0
package/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const fncs = require("./function");
|
|
2
|
+
const recordedjson = require("./tables");
|
|
3
|
+
const cstyler = require("cstyler");
|
|
4
|
+
const checker = require("./checker");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const moduleName = "databaser";
|
|
10
|
+
|
|
11
|
+
async function runit(config, table_json) {
|
|
12
|
+
try {
|
|
13
|
+
let errorLog = [];
|
|
14
|
+
let availabledbnames = [];
|
|
15
|
+
let unavailabledbnames = [];
|
|
16
|
+
// lets check database type
|
|
17
|
+
const ifmysqldatabase = await fncs.isMySQLDatabase(config);
|
|
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");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// Lets check both json file is same or not
|
|
23
|
+
if (fncs.isJsonObject(table_json)) {
|
|
24
|
+
if (fncs.isJsonSame(table_json, recordedjson)) {
|
|
25
|
+
console.log(cstyler.bold.italic.underline.green("All the tables are up to date. No changes needed"));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
console.error("Please provice a valid json file to continue.");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
console.log(cstyler.bold.underline.yellow("Table need an upgrade."))
|
|
33
|
+
// json file checking is done
|
|
34
|
+
const databaseNames = Object.keys(table_json);
|
|
35
|
+
if (Array.isArray(databaseNames)) {
|
|
36
|
+
for (let dbName of databaseNames) {
|
|
37
|
+
dbName = dbName.toLocaleLowerCase();
|
|
38
|
+
if (fncs.isValidDatabaseName(dbName)) {
|
|
39
|
+
const ifexist = await fncs.checkDatabaseExists(config, dbName);
|
|
40
|
+
if (ifexist === false) {
|
|
41
|
+
const createDB = await fncs.createDatabase(config, dbName);
|
|
42
|
+
if (createDB === true) {
|
|
43
|
+
console.log(`${cstyler.purpal('Database name:')} ${cstyler.blue(dbName)} ${cstyler.green('has created successfully.')}`)
|
|
44
|
+
} else if (createDB === false) {
|
|
45
|
+
console.log(`${cstyler.purpal('Database name:')} ${cstyler.blue(dbName)} ${cstyler.yellow("is already created.")}`)
|
|
46
|
+
} else {
|
|
47
|
+
throw new Error("Can not perform. There is a database connection problem.");
|
|
48
|
+
}
|
|
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
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
errorLog.push(`${cstyler.purpal('Database name:')} "${cstyler.yellow(dbName)}" ${cstyler.red("is not valid")}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Lets check how many database added
|
|
59
|
+
const getalldbnames = await fncs.getAllDatabaseNames(config);
|
|
60
|
+
if (getalldbnames === null) {
|
|
61
|
+
throw new Error("Can not perform. There is a database connection problem.");
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(getalldbnames)) {
|
|
64
|
+
for (const items of databaseNames) {
|
|
65
|
+
if (!getalldbnames.includes(items.toLocaleLowerCase())) {
|
|
66
|
+
unavailabledbnames.push(items.toLocaleLowerCase());
|
|
67
|
+
console.error(`${cstyler.purpal('Database name:')} ${items} is not available. Please try again.`);
|
|
68
|
+
} else {
|
|
69
|
+
availabledbnames.push(items.toLocaleLowerCase());
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (availabledbnames.length === 0) {
|
|
74
|
+
console.error("There is no available database to work on tables.");
|
|
75
|
+
}
|
|
76
|
+
// lets check all table name and column name
|
|
77
|
+
const checkeing = checker.JSONchecker(table_json);
|
|
78
|
+
if (checkeing === false) {
|
|
79
|
+
console.log(cstyler.bold.underline.red("Please correct those information and try again."))
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// table json file checking done
|
|
83
|
+
//
|
|
84
|
+
}
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error(err.message);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
const { DBInfo } = require("./app");
|
|
98
|
+
const tables = require("./user_tables");
|
|
99
|
+
runit(DBInfo, tables);
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dbtasker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "You can create database and table on your own with a lot of functionality.",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "Md Nasiruddin Ahmed",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"database",
|
|
11
|
+
"mysql",
|
|
12
|
+
"table",
|
|
13
|
+
"create",
|
|
14
|
+
"mysql2",
|
|
15
|
+
"alter",
|
|
16
|
+
"modify",
|
|
17
|
+
""
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"cstyler": "^1.0.0",
|
|
24
|
+
"mysql2": "^3.14.2"
|
|
25
|
+
}
|
|
26
|
+
}
|