Bugfixes
This commit is contained in:
parent
38a4dd3da2
commit
281f9adedb
@ -1,113 +0,0 @@
|
|||||||
// @ts-check
|
|
||||||
|
|
||||||
const fs = require("fs");
|
|
||||||
require("dotenv").config({ path: "./../.env" });
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
const dbHandler = require("./utils/dbHandler");
|
|
||||||
const varDatabaseDbHandler = require("./utils/varDatabaseDbHandler");
|
|
||||||
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
|
|
||||||
const userId = process.argv.indexOf("--userId") >= 0 ? process.argv[process.argv.indexOf("--userId") + 1] : null;
|
|
||||||
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
/** ****************************************************************************** */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grab Schema
|
|
||||||
*
|
|
||||||
* @description Grab Schema
|
|
||||||
*/
|
|
||||||
async function recoverMainJsonFromDb() {
|
|
||||||
if (!userId) {
|
|
||||||
console.log("No user Id provided");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const databases = await dbHandler({
|
|
||||||
query: `SELECT * FROM user_databases WHERE user_id = ?`,
|
|
||||||
values: [userId],
|
|
||||||
});
|
|
||||||
|
|
||||||
/** @type {*[]} */
|
|
||||||
const dbWrite = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < databases.length; i++) {
|
|
||||||
const { id, db_name, db_slug, db_full_name, db_image, db_description } = databases[i];
|
|
||||||
|
|
||||||
const dbObject = {
|
|
||||||
dbName: db_name,
|
|
||||||
dbSlug: db_slug,
|
|
||||||
dbFullName: db_full_name,
|
|
||||||
dbDescription: db_description,
|
|
||||||
dbImage: db_image,
|
|
||||||
/** @type {*[]} */
|
|
||||||
tables: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
const tables = await dbHandler({
|
|
||||||
query: `SELECT * FROM user_database_tables WHERE user_id = ? AND db_id = ?`,
|
|
||||||
values: [userId, id],
|
|
||||||
});
|
|
||||||
|
|
||||||
for (let j = 0; j < tables.length; j++) {
|
|
||||||
const { table_name, table_slug, table_description } = tables[j];
|
|
||||||
|
|
||||||
const tableObject = {
|
|
||||||
tableName: table_slug,
|
|
||||||
tableFullName: table_name,
|
|
||||||
/** @type {*[]} */
|
|
||||||
fields: [],
|
|
||||||
/** @type {*[]} */
|
|
||||||
indexes: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
const tableFields = await varDatabaseDbHandler({
|
|
||||||
database: db_full_name,
|
|
||||||
queryString: `SHOW COLUMNS FROM ${table_slug}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (tableFields) {
|
|
||||||
for (let k = 0; k < tableFields.length; k++) {
|
|
||||||
const { Field, Type, Null, Default, Key } = tableFields[k];
|
|
||||||
|
|
||||||
const fieldObject = {
|
|
||||||
fieldName: Field,
|
|
||||||
dataType: Type.toUpperCase(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (Default?.match(/./) && !Default?.match(/timestamp/i)) fieldObject["defaultValue"] = Default;
|
|
||||||
if (Key?.match(/pri/i)) {
|
|
||||||
fieldObject["primaryKey"] = true;
|
|
||||||
fieldObject["autoIncrement"] = true;
|
|
||||||
}
|
|
||||||
if (Default?.match(/timestamp/i)) fieldObject["defaultValueLiteral"] = Default;
|
|
||||||
if (Null?.match(/yes/i)) fieldObject["nullValue"] = true;
|
|
||||||
if (Null?.match(/no/i)) fieldObject["notNullValue"] = true;
|
|
||||||
|
|
||||||
tableObject.fields.push(fieldObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dbObject.tables.push(tableObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
dbWrite.push(dbObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(`./../jsonData/dbSchemas/users/user-${userId}/main.json`, JSON.stringify(dbWrite, null, 4), "utf-8");
|
|
||||||
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
recoverMainJsonFromDb();
|
|
@ -35,7 +35,7 @@ const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || "";
|
|||||||
* @param {string} [params.email]
|
* @param {string} [params.email]
|
||||||
* @param {string} params.clientId
|
* @param {string} params.clientId
|
||||||
* @param {string} params.clientSecret
|
* @param {string} params.clientSecret
|
||||||
* @param {string[]} [params.additionalFields]
|
* @param {object} [params.additionalFields]
|
||||||
* @param {import("../../../types/database-schema.td").DSQL_DatabaseSchemaType} params.dbSchema
|
* @param {import("../../../types/database-schema.td").DSQL_DatabaseSchemaType} params.dbSchema
|
||||||
*/
|
*/
|
||||||
async function localGithubAuth({ res, code, email, clientId, clientSecret, additionalFields, dbSchema }) {
|
async function localGithubAuth({ res, code, email, clientId, clientSecret, additionalFields, dbSchema }) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "datasquirel",
|
"name": "datasquirel",
|
||||||
"version": "1.7.6",
|
"version": "1.7.7",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
@ -43,7 +43,7 @@ const localGithubAuth = require("../../engine/user/social/github-auth");
|
|||||||
* @param {http.ServerResponse} params.response - HTTPS response object
|
* @param {http.ServerResponse} params.response - HTTPS response object
|
||||||
* @param {string} params.encryptionKey - Encryption key
|
* @param {string} params.encryptionKey - Encryption key
|
||||||
* @param {string} params.encryptionSalt - Encryption salt
|
* @param {string} params.encryptionSalt - Encryption salt
|
||||||
* @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object
|
* @param {object} [params.additionalFields] - Additional Fields to be added to the user object
|
||||||
*
|
*
|
||||||
* @returns { Promise<FunctionReturn | undefined> }
|
* @returns { Promise<FunctionReturn | undefined> }
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user