Updates
This commit is contained in:
parent
3437be2c08
commit
a429436939
@ -76,6 +76,10 @@ function createDbFromSchema(_a) {
|
||||
console.log("Schema Not Found!");
|
||||
return false;
|
||||
}
|
||||
// fs.writeFileSync(
|
||||
// `./.tmp/dbSchema.json`,
|
||||
// JSON.stringify(dbSchema, null, 4)
|
||||
// );
|
||||
const isMain = !userSchemaMainJSONFilePath;
|
||||
for (let i = 0; i < dbSchema.length; i++) {
|
||||
const database = dbSchema[i];
|
||||
|
@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabDbSSL;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const grab_dir_names_1 = __importDefault(require("./names/grab-dir-names"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
/**
|
||||
* # Grab SSL
|
||||
*/
|
||||
@ -16,10 +17,11 @@ function grabDbSSL() {
|
||||
maxscaleSSLCaCertFileFinal = maxscaleSSLCaCertFile;
|
||||
}
|
||||
catch (error) { }
|
||||
const caFilePath = process.env.DSQL_SSL_CA_CERT || maxscaleSSLCaCertFileFinal;
|
||||
if (!(caFilePath === null || caFilePath === void 0 ? void 0 : caFilePath.match(/./))) {
|
||||
const caProivdedPath = process.env.DSQL_SSL_CA_CERT || maxscaleSSLCaCertFileFinal;
|
||||
if (!(caProivdedPath === null || caProivdedPath === void 0 ? void 0 : caProivdedPath.match(/./))) {
|
||||
return undefined;
|
||||
}
|
||||
const caFilePath = path_1.default.resolve(process.cwd(), caProivdedPath);
|
||||
if (!fs_1.default.existsSync(caFilePath)) {
|
||||
console.log(`${caFilePath} does not exist`);
|
||||
return undefined;
|
||||
|
@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = createUserSQLUser;
|
||||
const generate_password_1 = require("generate-password");
|
||||
const dbHandler_1 = __importDefault(require("../functions/backend/dbHandler"));
|
||||
const crud_1 = __importDefault(require("./data-fetching/crud"));
|
||||
const grab_user_main_sql_user_name_1 = __importDefault(require("./grab-user-main-sql-user-name"));
|
||||
const grab_db_names_1 = __importDefault(require("./grab-db-names"));
|
||||
const handle_mariadb_user_creation_1 = require("../functions/web-app/mariadb-user/handle-mariadb-user-creation");
|
||||
@ -27,6 +28,20 @@ function createUserSQLUser(user) {
|
||||
noErrorLogs: true,
|
||||
});
|
||||
const newPassword = (0, generate_password_1.generate)({ length: 32 });
|
||||
const updateUser = yield (0, crud_1.default)({
|
||||
action: "update",
|
||||
table: "users",
|
||||
data: {
|
||||
mariadb_host: webHost,
|
||||
mariadb_user: mariaDBUsername,
|
||||
mariadb_pass: newPassword,
|
||||
},
|
||||
targetId: user.id,
|
||||
});
|
||||
if (!updateUser.success) {
|
||||
console.log("updateUser", updateUser);
|
||||
throw new Error(`Couldn't Update Users Table!`);
|
||||
}
|
||||
yield (0, handle_mariadb_user_creation_1.createNewSQLUser)({
|
||||
host: webHost,
|
||||
password: newPassword,
|
||||
|
@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabDbFullName;
|
||||
const app_names_1 = require("../dict/app-names");
|
||||
const slugify_1 = __importDefault(require("./slugify"));
|
||||
/**
|
||||
* # Grab full database name
|
||||
@ -19,7 +20,7 @@ function grabDbFullName({ dbName, userId, user, }) {
|
||||
if (!dbName) {
|
||||
return;
|
||||
}
|
||||
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
||||
const dbNamePrefix = app_names_1.AppNames["DsqlDbPrefix"];
|
||||
const parsedDbName = (0, slugify_1.default)(dbName, "_");
|
||||
const dbSlug = parsedDbName.replace(new RegExp(`${dbNamePrefix}_?\\d+_`), "");
|
||||
return (0, slugify_1.default)(`${dbNamePrefix}_${finalUserId}_${dbSlug}`, "_");
|
||||
|
@ -1,3 +1,4 @@
|
||||
import fs from "fs";
|
||||
import createTable from "../utils/createTable";
|
||||
import updateTable from "../utils/updateTable";
|
||||
import { DSQL_DatabaseSchemaType } from "../../types";
|
||||
@ -47,6 +48,11 @@ export default async function createDbFromSchema({
|
||||
return false;
|
||||
}
|
||||
|
||||
// fs.writeFileSync(
|
||||
// `./.tmp/dbSchema.json`,
|
||||
// JSON.stringify(dbSchema, null, 4)
|
||||
// );
|
||||
|
||||
const isMain = !userSchemaMainJSONFilePath;
|
||||
|
||||
for (let i = 0; i < dbSchema.length; i++) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import fs from "fs";
|
||||
import grabDirNames from "./names/grab-dir-names";
|
||||
import type { ConnectionConfig } from "mariadb";
|
||||
import path from "path";
|
||||
|
||||
type Return = ConnectionConfig["ssl"] | undefined;
|
||||
|
||||
@ -15,13 +16,15 @@ export default function grabDbSSL(): Return {
|
||||
maxscaleSSLCaCertFileFinal = maxscaleSSLCaCertFile;
|
||||
} catch (error) {}
|
||||
|
||||
const caFilePath =
|
||||
const caProivdedPath =
|
||||
process.env.DSQL_SSL_CA_CERT || maxscaleSSLCaCertFileFinal;
|
||||
|
||||
if (!caFilePath?.match(/./)) {
|
||||
if (!caProivdedPath?.match(/./)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const caFilePath = path.resolve(process.cwd(), caProivdedPath);
|
||||
|
||||
if (!fs.existsSync(caFilePath)) {
|
||||
console.log(`${caFilePath} does not exist`);
|
||||
return undefined;
|
||||
|
@ -35,6 +35,22 @@ export default async function createUserSQLUser(user: UserType) {
|
||||
|
||||
const newPassword = generate({ length: 32 });
|
||||
|
||||
const updateUser = await dsqlCrud<DSQL_DATASQUIREL_USERS>({
|
||||
action: "update",
|
||||
table: "users",
|
||||
data: {
|
||||
mariadb_host: webHost,
|
||||
mariadb_user: mariaDBUsername,
|
||||
mariadb_pass: newPassword,
|
||||
},
|
||||
targetId: user.id,
|
||||
});
|
||||
|
||||
if (!updateUser.success) {
|
||||
console.log("updateUser", updateUser);
|
||||
throw new Error(`Couldn't Update Users Table!`);
|
||||
}
|
||||
|
||||
await createNewSQLUser({
|
||||
host: webHost,
|
||||
password: newPassword,
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { AppNames } from "../dict/app-names";
|
||||
import { UserType } from "../types";
|
||||
import slugify from "./slugify";
|
||||
|
||||
@ -30,7 +31,7 @@ export default function grabDbFullName({
|
||||
return;
|
||||
}
|
||||
|
||||
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
||||
const dbNamePrefix = AppNames["DsqlDbPrefix"];
|
||||
|
||||
const parsedDbName = slugify(dbName, "_");
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "5.0.9",
|
||||
"version": "5.1.0",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
Loading…
Reference in New Issue
Block a user