main
HerrHase 1 year ago
parent 83d144dde1
commit b5c5353aa5

@ -0,0 +1,90 @@
import mysql from 'mysql2/promise'
import { input, password } from '@inquirer/prompts'
import generator from 'generate-password'
import chalk from 'chalk'
const log = console.log
/**
* mariadb-create.js
*
* create database and generate name, user, password
* and grant this user single priveleges
*
*
*/
const user = {
name: undefined,
password: undefined
}
user.name = await input({
message: 'Root:',
async validate(value) {
if (!value) {
return 'Required!'
}
return true
}
})
user.password = await password({
message: 'Password:',
mask: '*',
async validate(value) {
if (!value) {
return 'Required!'
}
return true
}
})
// create connection, generate name for db and user, and generate password
const connection = await mysql.createConnection({
host: 'localhost',
user: user.name,
password: user.password
})
const database = {
name: 'db',
user: 'u'
}
database.name += generator.generate({
length: 15,
numbers: true
})
database.user += generator.generate({
length: 15,
numbers: true
})
database.password = generator.generate({
length: 30,
numbers: true
})
// create database
await connection.query('CREATE DATABASE ' + database.name + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci')
await connection.query("CREATE USER " + database.user + "@'localhost' IDENTIFIED BY '" + database.password + "'")
await connection.query("CREATE USER " + database.user + "@'%' IDENTIFIED BY '" + database.password + "'")
await connection.query("GRANT ALL PRIVILEGES ON " + database.name + ".* TO " + database.user + "@localhost")
await connection.query("FLUSH PRIVILEGES")
connection.destroy()
// show name, user and passwort
log(' ')
log(chalk.green('Database created!'))
log(' ')
log(chalk.green('name:') + ' ' + chalk.cyan(database.name))
log(chalk.green('user:') + ' ' + chalk.cyan(database.user))
log(chalk.green('password:') + ' ' + chalk.cyan(database.password))

@ -1,6 +1,14 @@
import mysql from 'mysql2/promise' import mysql from 'mysql2/promise'
import { input, password } from '@inquirer/prompts' import { input, password } from '@inquirer/prompts'
import generator from 'generate-password'
/**
* mariadb-drop.js
*
* create database and generate name, user, password
* and grant this user single priveleges
*
*
*/
const user = { const user = {
name: undefined, name: undefined,

148
package-lock.json generated

@ -6,6 +6,7 @@
"": { "": {
"dependencies": { "dependencies": {
"@inquirer/prompts": "^3.2.0", "@inquirer/prompts": "^3.2.0",
"chalk": "^5.3.0",
"generate-password": "^1.7.1", "generate-password": "^1.7.1",
"mysql2": "^3.6.2" "mysql2": "^3.6.2"
} }
@ -25,6 +26,21 @@
"node": ">=14.18.0" "node": ">=14.18.0"
} }
}, },
"node_modules/@inquirer/checkbox/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/confirm": { "node_modules/@inquirer/confirm": {
"version": "2.0.14", "version": "2.0.14",
"resolved": "https://registry.npmjs.org/@inquirer/confirm/-/confirm-2.0.14.tgz", "resolved": "https://registry.npmjs.org/@inquirer/confirm/-/confirm-2.0.14.tgz",
@ -38,6 +54,21 @@
"node": ">=14.18.0" "node": ">=14.18.0"
} }
}, },
"node_modules/@inquirer/confirm/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/core": { "node_modules/@inquirer/core": {
"version": "5.1.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/@inquirer/core/-/core-5.1.0.tgz", "resolved": "https://registry.npmjs.org/@inquirer/core/-/core-5.1.0.tgz",
@ -62,6 +93,21 @@
"node": ">=14.18.0" "node": ">=14.18.0"
} }
}, },
"node_modules/@inquirer/core/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/editor": { "node_modules/@inquirer/editor": {
"version": "1.2.12", "version": "1.2.12",
"resolved": "https://registry.npmjs.org/@inquirer/editor/-/editor-1.2.12.tgz", "resolved": "https://registry.npmjs.org/@inquirer/editor/-/editor-1.2.12.tgz",
@ -76,6 +122,21 @@
"node": ">=14.18.0" "node": ">=14.18.0"
} }
}, },
"node_modules/@inquirer/editor/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/expand": { "node_modules/@inquirer/expand": {
"version": "1.1.13", "version": "1.1.13",
"resolved": "https://registry.npmjs.org/@inquirer/expand/-/expand-1.1.13.tgz", "resolved": "https://registry.npmjs.org/@inquirer/expand/-/expand-1.1.13.tgz",
@ -90,6 +151,21 @@
"node": ">=14.18.0" "node": ">=14.18.0"
} }
}, },
"node_modules/@inquirer/expand/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/input": { "node_modules/@inquirer/input": {
"version": "1.2.13", "version": "1.2.13",
"resolved": "https://registry.npmjs.org/@inquirer/input/-/input-1.2.13.tgz", "resolved": "https://registry.npmjs.org/@inquirer/input/-/input-1.2.13.tgz",
@ -103,6 +179,21 @@
"node": ">=14.18.0" "node": ">=14.18.0"
} }
}, },
"node_modules/@inquirer/input/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/password": { "node_modules/@inquirer/password": {
"version": "1.1.13", "version": "1.1.13",
"resolved": "https://registry.npmjs.org/@inquirer/password/-/password-1.1.13.tgz", "resolved": "https://registry.npmjs.org/@inquirer/password/-/password-1.1.13.tgz",
@ -117,6 +208,21 @@
"node": ">=14.18.0" "node": ">=14.18.0"
} }
}, },
"node_modules/@inquirer/password/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/prompts": { "node_modules/@inquirer/prompts": {
"version": "3.2.0", "version": "3.2.0",
"resolved": "https://registry.npmjs.org/@inquirer/prompts/-/prompts-3.2.0.tgz", "resolved": "https://registry.npmjs.org/@inquirer/prompts/-/prompts-3.2.0.tgz",
@ -149,6 +255,21 @@
"node": ">=14.18.0" "node": ">=14.18.0"
} }
}, },
"node_modules/@inquirer/rawlist/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/select": { "node_modules/@inquirer/select": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/@inquirer/select/-/select-1.3.0.tgz", "resolved": "https://registry.npmjs.org/@inquirer/select/-/select-1.3.0.tgz",
@ -164,6 +285,21 @@
"node": ">=14.18.0" "node": ">=14.18.0"
} }
}, },
"node_modules/@inquirer/select/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/@inquirer/type": { "node_modules/@inquirer/type": {
"version": "1.1.5", "version": "1.1.5",
"resolved": "https://registry.npmjs.org/@inquirer/type/-/type-1.1.5.tgz", "resolved": "https://registry.npmjs.org/@inquirer/type/-/type-1.1.5.tgz",
@ -230,15 +366,11 @@
} }
}, },
"node_modules/chalk": { "node_modules/chalk": {
"version": "4.1.2", "version": "5.3.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": { "engines": {
"node": ">=10" "node": "^12.17.0 || ^14.13 || >=16.0.0"
}, },
"funding": { "funding": {
"url": "https://github.com/chalk/chalk?sponsor=1" "url": "https://github.com/chalk/chalk?sponsor=1"

@ -3,6 +3,7 @@
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@inquirer/prompts": "^3.2.0", "@inquirer/prompts": "^3.2.0",
"chalk": "^5.3.0",
"generate-password": "^1.7.1", "generate-password": "^1.7.1",
"mysql2": "^3.6.2" "mysql2": "^3.6.2"
} }

Loading…
Cancel
Save