dsql-admin/dsql-app/shell/updateDbSlugsForTableRecords.js
2024-11-05 12:12:42 +01:00

59 lines
2.0 KiB
JavaScript
Executable File

// @ts-check
require("dotenv").config({ path: "./../.env" });
const DB_HANDLER = require("../package-shared/utils/backend/global-db/DB_HANDLER");
////////////////////////////////////////
const varDatabaseDbHandler = require("../package-shared/functions/backend/varDatabaseDbHandler");
const serverError = require("@/package-shared/functions/backend/serverError");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* Grab Schema
*
* @description Grab Schema
*/
varDatabaseDbHandler({
queryString: `SELECT DISTINCT db_id FROM user_database_tables`,
database: "datasquirel",
}).then(async (tables) => {
// console.log(tables);
// process.exit();
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 (/** @type {any} */ error) {
serverError({
component:
"shell/updateDbSlugsForTableRecords/main-catch-error",
message: error.message,
user: {},
});
}
}
process.exit();
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////