Upgrades
This commit is contained in:
parent
cb195616b3
commit
5f1f7da024
54
engine/dump.js
Normal file
54
engine/dump.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#! /usr/bin/env node
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const { execSync } = require("child_process");
|
||||||
|
|
||||||
|
require("dotenv").config({
|
||||||
|
path: path.resolve(process.cwd(), ".env"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const varDatabaseDbHandler = require("./engine/utils/varDatabaseDbHandler");
|
||||||
|
|
||||||
|
const mysqlPath = process.platform?.match(/win/i) ? "'" + "C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysql.exe" + "'" : "mysql";
|
||||||
|
const mysqlDumpPath = process.platform?.match(/win/i) ? "'" + "C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" + "'" : "mysqldump";
|
||||||
|
|
||||||
|
const dbName = process.env.DSQL_DB_NAME || "";
|
||||||
|
const dumpFilePathArg = process.argv.indexOf("--file");
|
||||||
|
|
||||||
|
if (dumpFilePathArg < 0) {
|
||||||
|
console.log("Please provide a dump file path using `--file` argument");
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
const dumpFilePath = process.argv[dumpFilePathArg + 1];
|
||||||
|
|
||||||
|
if (!dbName?.match(/./)) {
|
||||||
|
console.log("DSQL_DB_NAME is required in your `.env` file");
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
varDatabaseDbHandler({
|
||||||
|
queryString: `CREATE DATABASE \`${dbName}\` IF NOT EXISTS CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`,
|
||||||
|
database: dbName,
|
||||||
|
}).then((res) => {
|
||||||
|
console.log("Database creation attempt completed =>", res);
|
||||||
|
try {
|
||||||
|
let execSyncOptions = {
|
||||||
|
cwd: process.cwd(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (process.platform.match(/win/i)) execSyncOptions.shell = "bash.exe";
|
||||||
|
|
||||||
|
execSync(`${mysqlPath} -u ${process.env.DB_USERNAME} -p${process.env.DB_PASSWORD} ${dbName} < ${dumpFilePath}`, execSyncOptions);
|
||||||
|
|
||||||
|
console.log("Dumped successfully");
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
////////////////////////////////////////
|
||||||
|
////////////////////////////////////////
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Dump Error: ", error.message);
|
||||||
|
}
|
||||||
|
});
|
@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "datasquirel",
|
"name": "datasquirel",
|
||||||
"version": "1.5.5",
|
"version": "1.5.6",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"dsql-watch": "./engine/dsql.js"
|
"dsql-watch": "./engine/dsql.js",
|
||||||
|
"dsql-dump": "./engine/dump.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
Loading…
Reference in New Issue
Block a user