datasquirel/dist/package-shared/shell/updateDbSlugsForTableRecords.js
Benjamin Toby 7e8bb37c09 Updates
2025-07-05 14:59:30 +01:00

40 lines
1.7 KiB
JavaScript

require("dotenv").config({ path: "./../.env" });
import serverError from "../functions/backend/serverError";
import varDatabaseDbHandler from "./utils/varDatabaseDbHandler";
import DB_HANDLER from "../utils/backend/global-db/DB_HANDLER";
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* Grab Schema
*
* @description Grab Schema
*/
varDatabaseDbHandler({
queryString: `SELECT DISTINCT db_id FROM datasquirel.user_database_tables`,
}).then(async (tables) => {
// console.log(tables);
// process.exit();
var _a;
for (let i = 0; i < tables.length; i++) {
const table = tables[i];
try {
const { db_id } = table;
const dbSlug = await DB_HANDLER(`SELECT db_slug FROM user_databases WHERE id='${db_id}'`);
const updateTableSlug = await DB_HANDLER(`UPDATE user_database_tables SET db_slug='${dbSlug[0].db_slug}' WHERE db_id='${db_id}'`);
}
catch (error) {
serverError({
component: "shell/updateDbSlugsForTableRecords/main-catch-error",
message: error.message,
user: {},
});
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Error Updating DB Slugs For Table Records`, error);
}
}
process.exit();
});