@intecoag/inteco-cli 0.5.1 → 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/.github/workflows/publish.yml +31 -0
- package/README.md +3 -3
- package/package.json +44 -35
- package/src/index.js +85 -85
- package/src/modules/adbBridge.js +51 -51
- package/src/modules/adbIntentSender.js +81 -81
- package/src/modules/bundleProduct.js +160 -160
- package/src/modules/csvMerger.js +117 -117
- package/src/modules/deleteDB.js +83 -83
- package/src/modules/dumpDB.js +215 -215
- package/src/modules/dumpTableToCSV.js +153 -153
- package/src/modules/extdSearch.js +226 -226
- package/src/modules/graphqlSchemaExport.js +60 -60
- package/src/modules/importDB.js +120 -120
- package/src/modules/rewriteConfig.js +78 -78
- package/src/modules/setCLIConfig.js +32 -32
- package/src/modules/syncConfig.js +264 -264
- package/src/modules/t003Rewrite.js +63 -63
- package/src/ressources/cmds.json +46 -46
- package/src/utils/config/config.js +70 -70
- package/src/utils/config/default.json +8 -8
- package/src/utils/db/DB.js +53 -53
- package/src/utils/fs/FS.js +87 -87
package/src/modules/deleteDB.js
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import prompts from "prompts"
|
|
2
|
-
import { rmSync } from "fs";
|
|
3
|
-
import ora from "ora";
|
|
4
|
-
import { DB } from "../utils/db/DB.js";
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
import path from "path";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export default async function deleteDBMand(cli){
|
|
10
|
-
console.log()
|
|
11
|
-
|
|
12
|
-
const databaseNames = await DB.getDatabaseNames();
|
|
13
|
-
|
|
14
|
-
let success = true;
|
|
15
|
-
|
|
16
|
-
const results = await prompts([
|
|
17
|
-
{
|
|
18
|
-
// DB-Auswahl von DB
|
|
19
|
-
type: 'autocomplete',
|
|
20
|
-
name: 'dbName',
|
|
21
|
-
message: 'DB-Name?',
|
|
22
|
-
choices: databaseNames.map(name => { return { title: name.name } })
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
type: 'number',
|
|
26
|
-
name: 'mnr',
|
|
27
|
-
message: 'Mandant?',
|
|
28
|
-
initial: '1'
|
|
29
|
-
}
|
|
30
|
-
],{
|
|
31
|
-
onCancel: () => {
|
|
32
|
-
console.log()
|
|
33
|
-
console.log(chalk.red("Cancelled Import!"))
|
|
34
|
-
console.log()
|
|
35
|
-
success = false
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
if(success){
|
|
40
|
-
console.log()
|
|
41
|
-
|
|
42
|
-
const spinner = ora('Deleting in DB').start();
|
|
43
|
-
|
|
44
|
-
// Load table names
|
|
45
|
-
let tables = await DB.executeQueryOnDB("SHOW TABLES;", results.dbName);
|
|
46
|
-
const tableKey = Object.keys(tables[0])[0];
|
|
47
|
-
tables = tables.map(row => row[tableKey])
|
|
48
|
-
|
|
49
|
-
if(tables == null || tables.length == 0){
|
|
50
|
-
spinner.fail("Database has no tables: "+results.dbName)
|
|
51
|
-
}else{
|
|
52
|
-
// Remove previous dump
|
|
53
|
-
rmSync("."+path.sep+results.dumpName, {recursive:true, force:true})
|
|
54
|
-
for(const table of tables){
|
|
55
|
-
// Check if Mand-Column exists
|
|
56
|
-
const tableSpinner = ora("Deleting data: "+table).start();
|
|
57
|
-
const tableCol = table+"_mnr"
|
|
58
|
-
const columnExists = await DB.executeQueryOnDB("SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = '"+results.dbName+"' AND table_name = '"+table+"' AND column_name = '"+tableCol+"';")
|
|
59
|
-
|
|
60
|
-
if(columnExists [0]['COUNT(*)'] != 0){
|
|
61
|
-
// Check if Mand-Data is present
|
|
62
|
-
const dataExists = await DB.executeQueryOnDB("SELECT COUNT(*) FROM "+table+" WHERE "+tableCol+" = '"+results.mnr+"';", results.dbName);
|
|
63
|
-
|
|
64
|
-
if(dataExists[0]['COUNT(*)'] != 0){
|
|
65
|
-
await DB.executeQueryOnDB("DELETE FROM "+table+" WHERE "+tableCol+" = '"+results.mnr+"';", results.dbName)
|
|
66
|
-
tableSpinner.succeed("Data deleted: "+table);
|
|
67
|
-
}else{
|
|
68
|
-
tableSpinner.info("No data present, Skipping table: "+table)
|
|
69
|
-
}
|
|
70
|
-
}else{
|
|
71
|
-
tableSpinner.info("Column "+tableCol+" not found, Skipping table: "+table)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Dump mand-table (special field name)
|
|
75
|
-
const tableSpinner = ora("Deleting mand (custom logic)")
|
|
76
|
-
await DB.executeQueryOnDB("DELETE FROM mand WHERE mand_mandant = '"+results.mnr+"';", results.dbName)
|
|
77
|
-
tableSpinner.succeed("Data deleted: mand")
|
|
78
|
-
spinner.succeed("Mand deleted: "+results.mnr);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
console.log();
|
|
83
|
-
}
|
|
1
|
+
import prompts from "prompts"
|
|
2
|
+
import { rmSync } from "fs";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { DB } from "../utils/db/DB.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import path from "path";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export default async function deleteDBMand(cli){
|
|
10
|
+
console.log()
|
|
11
|
+
|
|
12
|
+
const databaseNames = await DB.getDatabaseNames();
|
|
13
|
+
|
|
14
|
+
let success = true;
|
|
15
|
+
|
|
16
|
+
const results = await prompts([
|
|
17
|
+
{
|
|
18
|
+
// DB-Auswahl von DB
|
|
19
|
+
type: 'autocomplete',
|
|
20
|
+
name: 'dbName',
|
|
21
|
+
message: 'DB-Name?',
|
|
22
|
+
choices: databaseNames.map(name => { return { title: name.name } })
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: 'number',
|
|
26
|
+
name: 'mnr',
|
|
27
|
+
message: 'Mandant?',
|
|
28
|
+
initial: '1'
|
|
29
|
+
}
|
|
30
|
+
],{
|
|
31
|
+
onCancel: () => {
|
|
32
|
+
console.log()
|
|
33
|
+
console.log(chalk.red("Cancelled Import!"))
|
|
34
|
+
console.log()
|
|
35
|
+
success = false
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
if(success){
|
|
40
|
+
console.log()
|
|
41
|
+
|
|
42
|
+
const spinner = ora('Deleting in DB').start();
|
|
43
|
+
|
|
44
|
+
// Load table names
|
|
45
|
+
let tables = await DB.executeQueryOnDB("SHOW TABLES;", results.dbName);
|
|
46
|
+
const tableKey = Object.keys(tables[0])[0];
|
|
47
|
+
tables = tables.map(row => row[tableKey])
|
|
48
|
+
|
|
49
|
+
if(tables == null || tables.length == 0){
|
|
50
|
+
spinner.fail("Database has no tables: "+results.dbName)
|
|
51
|
+
}else{
|
|
52
|
+
// Remove previous dump
|
|
53
|
+
rmSync("."+path.sep+results.dumpName, {recursive:true, force:true})
|
|
54
|
+
for(const table of tables){
|
|
55
|
+
// Check if Mand-Column exists
|
|
56
|
+
const tableSpinner = ora("Deleting data: "+table).start();
|
|
57
|
+
const tableCol = table+"_mnr"
|
|
58
|
+
const columnExists = await DB.executeQueryOnDB("SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = '"+results.dbName+"' AND table_name = '"+table+"' AND column_name = '"+tableCol+"';")
|
|
59
|
+
|
|
60
|
+
if(columnExists [0]['COUNT(*)'] != 0){
|
|
61
|
+
// Check if Mand-Data is present
|
|
62
|
+
const dataExists = await DB.executeQueryOnDB("SELECT COUNT(*) FROM "+table+" WHERE "+tableCol+" = '"+results.mnr+"';", results.dbName);
|
|
63
|
+
|
|
64
|
+
if(dataExists[0]['COUNT(*)'] != 0){
|
|
65
|
+
await DB.executeQueryOnDB("DELETE FROM "+table+" WHERE "+tableCol+" = '"+results.mnr+"';", results.dbName)
|
|
66
|
+
tableSpinner.succeed("Data deleted: "+table);
|
|
67
|
+
}else{
|
|
68
|
+
tableSpinner.info("No data present, Skipping table: "+table)
|
|
69
|
+
}
|
|
70
|
+
}else{
|
|
71
|
+
tableSpinner.info("Column "+tableCol+" not found, Skipping table: "+table)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Dump mand-table (special field name)
|
|
75
|
+
const tableSpinner = ora("Deleting mand (custom logic)")
|
|
76
|
+
await DB.executeQueryOnDB("DELETE FROM mand WHERE mand_mandant = '"+results.mnr+"';", results.dbName)
|
|
77
|
+
tableSpinner.succeed("Data deleted: mand")
|
|
78
|
+
spinner.succeed("Mand deleted: "+results.mnr);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
console.log();
|
|
83
|
+
}
|
|
84
84
|
}
|
package/src/modules/dumpDB.js
CHANGED
|
@@ -1,216 +1,216 @@
|
|
|
1
|
-
import prompts from "prompts"
|
|
2
|
-
import { rmSync } from "fs";
|
|
3
|
-
import ora from "ora";
|
|
4
|
-
import { DB } from "../utils/db/DB.js";
|
|
5
|
-
import { Config } from "../utils/config/config.js";
|
|
6
|
-
import chalk from "chalk";
|
|
7
|
-
import path from "path";
|
|
8
|
-
import { exec, execSync } from "child_process";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export async function dumpDB(cli) {
|
|
12
|
-
console.log()
|
|
13
|
-
|
|
14
|
-
const config = await Config.getConfig();
|
|
15
|
-
|
|
16
|
-
const databaseNames = await DB.getDatabaseNames();
|
|
17
|
-
|
|
18
|
-
let success = true;
|
|
19
|
-
|
|
20
|
-
const resultsDB = await prompts([
|
|
21
|
-
{
|
|
22
|
-
// DB-Auswahl von DB
|
|
23
|
-
type: 'autocomplete',
|
|
24
|
-
name: 'dbName',
|
|
25
|
-
message: 'DB-Name?',
|
|
26
|
-
choices: databaseNames.map(name => { return { title: name.name } })
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
type: 'toggle',
|
|
30
|
-
name: 'dataOnly',
|
|
31
|
-
message: 'Dump data only (no table recreation)?',
|
|
32
|
-
initial: false,
|
|
33
|
-
active: 'yes',
|
|
34
|
-
inactive: 'no'
|
|
35
|
-
}
|
|
36
|
-
, {
|
|
37
|
-
type: 'toggle',
|
|
38
|
-
name: 'selectIndividualTables',
|
|
39
|
-
message: 'Select individual tables?',
|
|
40
|
-
initial: false,
|
|
41
|
-
active: 'yes',
|
|
42
|
-
inactive: 'no'
|
|
43
|
-
}], {
|
|
44
|
-
onCancel: () => {
|
|
45
|
-
console.log()
|
|
46
|
-
console.log(chalk.red("Cancelled Import!"))
|
|
47
|
-
console.log()
|
|
48
|
-
success = false
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
if (success) {
|
|
53
|
-
let selectedTables = [];
|
|
54
|
-
if (resultsDB.selectIndividualTables) {
|
|
55
|
-
|
|
56
|
-
let tables = await DB.executeQueryOnDB("SHOW TABLES;", resultsDB.dbName);
|
|
57
|
-
const tableKey = Object.keys(tables[0])[0];
|
|
58
|
-
tables = tables.map(row => row[tableKey])
|
|
59
|
-
let continuePrompt = true;
|
|
60
|
-
while (continuePrompt) {
|
|
61
|
-
const resultsTable = await prompts([
|
|
62
|
-
{
|
|
63
|
-
// DB-Auswahl von DB
|
|
64
|
-
type: 'autocomplete',
|
|
65
|
-
name: 'table',
|
|
66
|
-
message: 'Table?',
|
|
67
|
-
choices: tables.map(name => { return { title: name } }),
|
|
68
|
-
default: ""
|
|
69
|
-
}, {
|
|
70
|
-
type: 'toggle',
|
|
71
|
-
name: 'continue',
|
|
72
|
-
message: 'Add another table?',
|
|
73
|
-
initial: false,
|
|
74
|
-
active: 'yes',
|
|
75
|
-
inactive: 'no'
|
|
76
|
-
}], {
|
|
77
|
-
onCancel: () => {
|
|
78
|
-
console.log()
|
|
79
|
-
console.log(chalk.red("Cancelled Import!"))
|
|
80
|
-
console.log()
|
|
81
|
-
success = false
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
selectedTables.push(resultsTable.table)
|
|
86
|
-
continuePrompt = resultsTable.continue
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const results = await prompts([
|
|
92
|
-
{
|
|
93
|
-
// Ordnerauswahl von vorhandenen Ordner in configIndividual
|
|
94
|
-
type: 'text',
|
|
95
|
-
name: 'dumpName',
|
|
96
|
-
message: 'Dump-Name?',
|
|
97
|
-
initial: 'dump.sql'
|
|
98
|
-
}
|
|
99
|
-
], {
|
|
100
|
-
onCancel: () => {
|
|
101
|
-
console.log()
|
|
102
|
-
console.log(chalk.red("Cancelled Import!"))
|
|
103
|
-
console.log()
|
|
104
|
-
success = false
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
if (success) {
|
|
109
|
-
console.log()
|
|
110
|
-
const spinner = ora('Dumping DB').start();
|
|
111
|
-
|
|
112
|
-
const dumpCommand = `mysqldump ${resultsDB.dataOnly?'--no-create-info':''} -u${config.dbUser} -p${config.dbPassword} -h${config.dbURL} ${resultsDB.dbName} ${selectedTables.join(" ")} > ${results.dumpName}`;
|
|
113
|
-
|
|
114
|
-
exec(dumpCommand, (error, stdout, stderr) => {
|
|
115
|
-
if (error) {
|
|
116
|
-
spinner.fail('Failed to dump DB');
|
|
117
|
-
console.error(error);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
spinner.succeed("Dumped DB to " + results.dumpName);
|
|
122
|
-
console.log();
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export async function dumpDBMand(cli) {
|
|
131
|
-
console.log()
|
|
132
|
-
|
|
133
|
-
const config = await Config.getConfig();
|
|
134
|
-
|
|
135
|
-
const databaseNames = await DB.getDatabaseNames();
|
|
136
|
-
|
|
137
|
-
let success = true;
|
|
138
|
-
|
|
139
|
-
const results = await prompts([
|
|
140
|
-
{
|
|
141
|
-
// DB-Auswahl von DB
|
|
142
|
-
type: 'autocomplete',
|
|
143
|
-
name: 'dbName',
|
|
144
|
-
message: 'DB-Name?',
|
|
145
|
-
choices: databaseNames.map(name => { return { title: name.name } })
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
type: 'number',
|
|
149
|
-
name: 'mnr',
|
|
150
|
-
message: 'Mandant?',
|
|
151
|
-
initial: '1'
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
// Ordnerauswahl von vorhandenen Ordner in configIndividual
|
|
155
|
-
type: 'text',
|
|
156
|
-
name: 'dumpName',
|
|
157
|
-
message: 'Dump-Name?',
|
|
158
|
-
initial: 'dump.sql'
|
|
159
|
-
}
|
|
160
|
-
], {
|
|
161
|
-
onCancel: () => {
|
|
162
|
-
console.log()
|
|
163
|
-
console.log(chalk.red("Cancelled Import!"))
|
|
164
|
-
console.log()
|
|
165
|
-
success = false
|
|
166
|
-
}
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
if (success) {
|
|
170
|
-
console.log()
|
|
171
|
-
|
|
172
|
-
const spinner = ora('Dumping DB').start();
|
|
173
|
-
|
|
174
|
-
// Load table names
|
|
175
|
-
let tables = await DB.executeQueryOnDB("SHOW TABLES;", results.dbName);
|
|
176
|
-
const tableKey = Object.keys(tables[0])[0];
|
|
177
|
-
tables = tables.map(row => row[tableKey])
|
|
178
|
-
|
|
179
|
-
if (tables == null || tables.length == 0) {
|
|
180
|
-
spinner.fail("Database has no tables: " + results.dbName)
|
|
181
|
-
} else {
|
|
182
|
-
// Remove previous dump
|
|
183
|
-
rmSync("." + path.sep + results.dumpName, { recursive: true, force: true })
|
|
184
|
-
for (const table of tables) {
|
|
185
|
-
// Check if Mand-Column exists
|
|
186
|
-
const tableSpinner = ora("Dumping data: " + table).start();
|
|
187
|
-
const tableCol = table + "_mnr"
|
|
188
|
-
const columnExists = await DB.executeQueryOnDB("SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = '" + results.dbName + "' AND table_name = '" + table + "' AND column_name = '" + tableCol + "';")
|
|
189
|
-
|
|
190
|
-
if (columnExists[0]['COUNT(*)'] != 0) {
|
|
191
|
-
// Check if Mand-Data is present
|
|
192
|
-
const dataExists = await DB.executeQueryOnDB("SELECT COUNT(*) FROM " + table + " WHERE " + tableCol + " = '" + results.mnr + "';", results.dbName);
|
|
193
|
-
|
|
194
|
-
if (dataExists[0]['COUNT(*)'] != 0) {
|
|
195
|
-
// Dump table
|
|
196
|
-
execSync("mysqldump -u" + config.dbUser + " -p" + config.dbPassword + " -h" + config.dbURL + " --no-create-info --where=\"" + tableCol + " = '" + results.mnr + "'\" " + results.dbName + " " + table + " >> " + results.dumpName);
|
|
197
|
-
|
|
198
|
-
tableSpinner.succeed("Data dumped: " + table);
|
|
199
|
-
} else {
|
|
200
|
-
tableSpinner.info("No data present, Skipping table: " + table)
|
|
201
|
-
}
|
|
202
|
-
} else {
|
|
203
|
-
tableSpinner.info("Column " + tableCol + " not found, Skipping table: " + table)
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
// Dump mand-table (special field name)
|
|
207
|
-
const tableSpinner = ora("Dumping mand (custom logic)")
|
|
208
|
-
execSync("mysqldump -u" + config.dbUser + " -p" + config.dbPassword + " -h" + config.dbURL + " --no-create-info --where=\"mand_mandant = '" + results.mnr + "'\" " + results.dbName + " mand >> " + results.dumpName);
|
|
209
|
-
tableSpinner.succeed("Data dumped: mand")
|
|
210
|
-
spinner.succeed("Dumped DB to " + results.dumpName);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
console.log();
|
|
215
|
-
}
|
|
1
|
+
import prompts from "prompts"
|
|
2
|
+
import { rmSync } from "fs";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { DB } from "../utils/db/DB.js";
|
|
5
|
+
import { Config } from "../utils/config/config.js";
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { exec, execSync } from "child_process";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export async function dumpDB(cli) {
|
|
12
|
+
console.log()
|
|
13
|
+
|
|
14
|
+
const config = await Config.getConfig();
|
|
15
|
+
|
|
16
|
+
const databaseNames = await DB.getDatabaseNames();
|
|
17
|
+
|
|
18
|
+
let success = true;
|
|
19
|
+
|
|
20
|
+
const resultsDB = await prompts([
|
|
21
|
+
{
|
|
22
|
+
// DB-Auswahl von DB
|
|
23
|
+
type: 'autocomplete',
|
|
24
|
+
name: 'dbName',
|
|
25
|
+
message: 'DB-Name?',
|
|
26
|
+
choices: databaseNames.map(name => { return { title: name.name } })
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 'toggle',
|
|
30
|
+
name: 'dataOnly',
|
|
31
|
+
message: 'Dump data only (no table recreation)?',
|
|
32
|
+
initial: false,
|
|
33
|
+
active: 'yes',
|
|
34
|
+
inactive: 'no'
|
|
35
|
+
}
|
|
36
|
+
, {
|
|
37
|
+
type: 'toggle',
|
|
38
|
+
name: 'selectIndividualTables',
|
|
39
|
+
message: 'Select individual tables?',
|
|
40
|
+
initial: false,
|
|
41
|
+
active: 'yes',
|
|
42
|
+
inactive: 'no'
|
|
43
|
+
}], {
|
|
44
|
+
onCancel: () => {
|
|
45
|
+
console.log()
|
|
46
|
+
console.log(chalk.red("Cancelled Import!"))
|
|
47
|
+
console.log()
|
|
48
|
+
success = false
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
if (success) {
|
|
53
|
+
let selectedTables = [];
|
|
54
|
+
if (resultsDB.selectIndividualTables) {
|
|
55
|
+
|
|
56
|
+
let tables = await DB.executeQueryOnDB("SHOW TABLES;", resultsDB.dbName);
|
|
57
|
+
const tableKey = Object.keys(tables[0])[0];
|
|
58
|
+
tables = tables.map(row => row[tableKey])
|
|
59
|
+
let continuePrompt = true;
|
|
60
|
+
while (continuePrompt) {
|
|
61
|
+
const resultsTable = await prompts([
|
|
62
|
+
{
|
|
63
|
+
// DB-Auswahl von DB
|
|
64
|
+
type: 'autocomplete',
|
|
65
|
+
name: 'table',
|
|
66
|
+
message: 'Table?',
|
|
67
|
+
choices: tables.map(name => { return { title: name } }),
|
|
68
|
+
default: ""
|
|
69
|
+
}, {
|
|
70
|
+
type: 'toggle',
|
|
71
|
+
name: 'continue',
|
|
72
|
+
message: 'Add another table?',
|
|
73
|
+
initial: false,
|
|
74
|
+
active: 'yes',
|
|
75
|
+
inactive: 'no'
|
|
76
|
+
}], {
|
|
77
|
+
onCancel: () => {
|
|
78
|
+
console.log()
|
|
79
|
+
console.log(chalk.red("Cancelled Import!"))
|
|
80
|
+
console.log()
|
|
81
|
+
success = false
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
selectedTables.push(resultsTable.table)
|
|
86
|
+
continuePrompt = resultsTable.continue
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const results = await prompts([
|
|
92
|
+
{
|
|
93
|
+
// Ordnerauswahl von vorhandenen Ordner in configIndividual
|
|
94
|
+
type: 'text',
|
|
95
|
+
name: 'dumpName',
|
|
96
|
+
message: 'Dump-Name?',
|
|
97
|
+
initial: 'dump.sql'
|
|
98
|
+
}
|
|
99
|
+
], {
|
|
100
|
+
onCancel: () => {
|
|
101
|
+
console.log()
|
|
102
|
+
console.log(chalk.red("Cancelled Import!"))
|
|
103
|
+
console.log()
|
|
104
|
+
success = false
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
if (success) {
|
|
109
|
+
console.log()
|
|
110
|
+
const spinner = ora('Dumping DB').start();
|
|
111
|
+
|
|
112
|
+
const dumpCommand = `mysqldump ${resultsDB.dataOnly?'--no-create-info':''} -u${config.dbUser} -p${config.dbPassword} -h${config.dbURL} ${resultsDB.dbName} ${selectedTables.join(" ")} > ${results.dumpName}`;
|
|
113
|
+
|
|
114
|
+
exec(dumpCommand, (error, stdout, stderr) => {
|
|
115
|
+
if (error) {
|
|
116
|
+
spinner.fail('Failed to dump DB');
|
|
117
|
+
console.error(error);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
spinner.succeed("Dumped DB to " + results.dumpName);
|
|
122
|
+
console.log();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function dumpDBMand(cli) {
|
|
131
|
+
console.log()
|
|
132
|
+
|
|
133
|
+
const config = await Config.getConfig();
|
|
134
|
+
|
|
135
|
+
const databaseNames = await DB.getDatabaseNames();
|
|
136
|
+
|
|
137
|
+
let success = true;
|
|
138
|
+
|
|
139
|
+
const results = await prompts([
|
|
140
|
+
{
|
|
141
|
+
// DB-Auswahl von DB
|
|
142
|
+
type: 'autocomplete',
|
|
143
|
+
name: 'dbName',
|
|
144
|
+
message: 'DB-Name?',
|
|
145
|
+
choices: databaseNames.map(name => { return { title: name.name } })
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
type: 'number',
|
|
149
|
+
name: 'mnr',
|
|
150
|
+
message: 'Mandant?',
|
|
151
|
+
initial: '1'
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
// Ordnerauswahl von vorhandenen Ordner in configIndividual
|
|
155
|
+
type: 'text',
|
|
156
|
+
name: 'dumpName',
|
|
157
|
+
message: 'Dump-Name?',
|
|
158
|
+
initial: 'dump.sql'
|
|
159
|
+
}
|
|
160
|
+
], {
|
|
161
|
+
onCancel: () => {
|
|
162
|
+
console.log()
|
|
163
|
+
console.log(chalk.red("Cancelled Import!"))
|
|
164
|
+
console.log()
|
|
165
|
+
success = false
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
if (success) {
|
|
170
|
+
console.log()
|
|
171
|
+
|
|
172
|
+
const spinner = ora('Dumping DB').start();
|
|
173
|
+
|
|
174
|
+
// Load table names
|
|
175
|
+
let tables = await DB.executeQueryOnDB("SHOW TABLES;", results.dbName);
|
|
176
|
+
const tableKey = Object.keys(tables[0])[0];
|
|
177
|
+
tables = tables.map(row => row[tableKey])
|
|
178
|
+
|
|
179
|
+
if (tables == null || tables.length == 0) {
|
|
180
|
+
spinner.fail("Database has no tables: " + results.dbName)
|
|
181
|
+
} else {
|
|
182
|
+
// Remove previous dump
|
|
183
|
+
rmSync("." + path.sep + results.dumpName, { recursive: true, force: true })
|
|
184
|
+
for (const table of tables) {
|
|
185
|
+
// Check if Mand-Column exists
|
|
186
|
+
const tableSpinner = ora("Dumping data: " + table).start();
|
|
187
|
+
const tableCol = table + "_mnr"
|
|
188
|
+
const columnExists = await DB.executeQueryOnDB("SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = '" + results.dbName + "' AND table_name = '" + table + "' AND column_name = '" + tableCol + "';")
|
|
189
|
+
|
|
190
|
+
if (columnExists[0]['COUNT(*)'] != 0) {
|
|
191
|
+
// Check if Mand-Data is present
|
|
192
|
+
const dataExists = await DB.executeQueryOnDB("SELECT COUNT(*) FROM " + table + " WHERE " + tableCol + " = '" + results.mnr + "';", results.dbName);
|
|
193
|
+
|
|
194
|
+
if (dataExists[0]['COUNT(*)'] != 0) {
|
|
195
|
+
// Dump table
|
|
196
|
+
execSync("mysqldump -u" + config.dbUser + " -p" + config.dbPassword + " -h" + config.dbURL + " --no-create-info --where=\"" + tableCol + " = '" + results.mnr + "'\" " + results.dbName + " " + table + " >> " + results.dumpName);
|
|
197
|
+
|
|
198
|
+
tableSpinner.succeed("Data dumped: " + table);
|
|
199
|
+
} else {
|
|
200
|
+
tableSpinner.info("No data present, Skipping table: " + table)
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
tableSpinner.info("Column " + tableCol + " not found, Skipping table: " + table)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Dump mand-table (special field name)
|
|
207
|
+
const tableSpinner = ora("Dumping mand (custom logic)")
|
|
208
|
+
execSync("mysqldump -u" + config.dbUser + " -p" + config.dbPassword + " -h" + config.dbURL + " --no-create-info --where=\"mand_mandant = '" + results.mnr + "'\" " + results.dbName + " mand >> " + results.dumpName);
|
|
209
|
+
tableSpinner.succeed("Data dumped: mand")
|
|
210
|
+
spinner.succeed("Dumped DB to " + results.dumpName);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
console.log();
|
|
215
|
+
}
|
|
216
216
|
}
|