Bugfix
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import _ from "lodash";
|
||||
import serverError from "../../backend/serverError";
|
||||
import runQuery, { DbContextsArray } from "../../backend/db/runQuery";
|
||||
@@ -7,7 +5,6 @@ import {
|
||||
ApiGetQueryObject,
|
||||
DSQL_TableSchemaType,
|
||||
GetReturn,
|
||||
ServerQueryParam,
|
||||
} from "../../../types";
|
||||
import apiGetGrabQueryAndValues from "../../../utils/grab-query-and-values";
|
||||
|
||||
@@ -40,10 +37,7 @@ export default async function apiGet<
|
||||
values: queryValues,
|
||||
});
|
||||
|
||||
if (
|
||||
typeof query == "string" &&
|
||||
query.match(/^alter|^delete|information_schema|databases|^create/i)
|
||||
) {
|
||||
if (typeof query == "string" && query.match(/^alter|^delete|^create/i)) {
|
||||
return { success: false, msg: "Wrong Input." };
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import updateTable from "./utils/updateTable";
|
||||
import dbHandler from "./utils/dbHandler";
|
||||
import EJSON from "../utils/ejson";
|
||||
import { DSQL_DatabaseSchemaType } from "../types";
|
||||
import grabDirNames from "@/utils/backend/names/grab-dir-names";
|
||||
|
||||
type Param = {
|
||||
userId?: number | string | null;
|
||||
@@ -24,12 +25,11 @@ export default async function createDbFromSchema({
|
||||
targetDatabase,
|
||||
dbSchemaData,
|
||||
}: Param) {
|
||||
const schemaPath = userId
|
||||
? path.join(
|
||||
String(process.env.DSQL_USER_DB_SCHEMA_PATH),
|
||||
`/user-${userId}/main.json`
|
||||
)
|
||||
: path.resolve(__dirname, "../../jsonData/dbSchemas/main.json");
|
||||
const { userSchemaMainJSONFilePath, mainShemaJSONFilePath } = grabDirNames({
|
||||
userId,
|
||||
});
|
||||
|
||||
const schemaPath = userSchemaMainJSONFilePath || mainShemaJSONFilePath;
|
||||
|
||||
const dbSchema: DSQL_DatabaseSchemaType[] | undefined =
|
||||
dbSchemaData ||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { execSync, ExecSyncOptions } from "child_process";
|
||||
import os from "os";
|
||||
|
||||
export type ExportMariaDBDatabaseParam = {
|
||||
dbFullName: string;
|
||||
targetFilePath: string;
|
||||
mariadbUser?: string;
|
||||
mariadbHost?: string;
|
||||
mariadbPass?: string;
|
||||
};
|
||||
|
||||
export default function exportMariadbDatabase({
|
||||
dbFullName,
|
||||
targetFilePath,
|
||||
mariadbHost,
|
||||
mariadbPass,
|
||||
mariadbUser,
|
||||
}: ExportMariaDBDatabaseParam) {
|
||||
const mysqlDumpPath = os.platform().match(/win/i)
|
||||
? "'" +
|
||||
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" +
|
||||
"'"
|
||||
: "mysqldump";
|
||||
|
||||
const finalMariadbUser = mariadbUser || process.env.DSQL_DB_USERNAME;
|
||||
const finalMariadbHost = mariadbHost || process.env.DSQL_DB_HOST;
|
||||
const finalMariadbPass = mariadbPass || process.env.DSQL_DB_PASSWORD;
|
||||
|
||||
const cmd = `${mysqlDumpPath} -u ${finalMariadbUser} -h ${finalMariadbHost} -p${finalMariadbPass} ${dbFullName} > ${targetFilePath}`;
|
||||
|
||||
let execSyncOptions: ExecSyncOptions = {
|
||||
encoding: "utf-8",
|
||||
};
|
||||
|
||||
const dumpDb = execSync(cmd, execSyncOptions);
|
||||
|
||||
return dumpDb;
|
||||
}
|
||||
Reference in New Issue
Block a user