58 lines
3.2 KiB
JavaScript
58 lines
3.2 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const DB_HANDLER_1 = __importDefault(require("../utils/backend/global-db/DB_HANDLER"));
|
|
const fs_1 = __importDefault(require("fs"));
|
|
require("dotenv").config({ path: "./../.env" });
|
|
function updateChildrenTablesOnDb() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
var _a;
|
|
/**
|
|
* Grab Schema
|
|
*
|
|
* @description Grab Schema
|
|
*/
|
|
try {
|
|
const rootDir = String(process.env.DSQL_USER_DB_SCHEMA_PATH);
|
|
const userFolders = fs_1.default.readdirSync(rootDir);
|
|
for (let i = 0; i < userFolders.length; i++) {
|
|
const folder = userFolders[i];
|
|
const userId = folder.replace(/user-/, "");
|
|
const databases = JSON.parse(fs_1.default.readFileSync(`${rootDir}/${folder}/main.json`, "utf-8"));
|
|
for (let j = 0; j < databases.length; j++) {
|
|
const db = databases[j];
|
|
const dbTables = db.tables;
|
|
for (let k = 0; k < dbTables.length; k++) {
|
|
const table = dbTables[k];
|
|
if (table === null || table === void 0 ? void 0 : table.childTable) {
|
|
const originTableName = table.childTableName;
|
|
const originDbName = table.childTableDbFullName;
|
|
const WHERE_CLAUSE = `WHERE user_id='${userId}' AND db_slug='${db.dbSlug}' AND table_slug='${table.tableName}'`;
|
|
const existingTableInDb = yield (0, DB_HANDLER_1.default)(`SELECT * FROM user_database_tables ${WHERE_CLAUSE}`);
|
|
if (existingTableInDb && existingTableInDb[0]) {
|
|
const updateChildrenTablesInfo = yield (0, DB_HANDLER_1.default)(`UPDATE user_database_tables SET child_table='1',child_table_parent_database='${originDbName}',child_table_parent_table='${originTableName}' WHERE id='${existingTableInDb[0].id}'`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (error) {
|
|
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Error Updating Children Tables on DB`, error);
|
|
}
|
|
process.exit();
|
|
});
|
|
}
|
|
updateChildrenTablesOnDb();
|