feat(lstv2 move): moved lstv2 into this app to keep them combined and easier to maintain
This commit is contained in:
48
lstV2/server/services/sqlServer/utils/ocmeServerConfig.ts
Normal file
48
lstV2/server/services/sqlServer/utils/ocmeServerConfig.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import sql from "mssql";
|
||||
|
||||
// hardcoding everything to make sure it all works as intended
|
||||
const server = "usday1vms010";
|
||||
const dbUser = "ocme";
|
||||
const dbPassword = "Democrat-Humongous";
|
||||
|
||||
export const sqlConfig_ocme = {
|
||||
server: server,
|
||||
database: `Alpla_lst`,
|
||||
user: dbUser,
|
||||
password: dbPassword,
|
||||
options: {
|
||||
encrypt: true,
|
||||
trustServerCertificate: true,
|
||||
},
|
||||
requestTimeout: 90000, // in milliseconds
|
||||
// ocmePool: {
|
||||
// max: 20, // Maximum number of connections in the pool
|
||||
// min: 0, // Minimum number of connections in the pool
|
||||
// idleTimeoutMillis: 10000, // How long a connection is allowed to be idle before being released
|
||||
// reapIntervalMillis: 1000, // how often to check for idle resourses to destory
|
||||
// acquireTimeoutMillis: 100000, // How long until a complete timeout happens
|
||||
// },
|
||||
};
|
||||
|
||||
export async function runQuery(queryToRun: string, name: string) {
|
||||
let connection;
|
||||
try {
|
||||
// Establish a direct connection to the different server
|
||||
connection = await sql.connect(sqlConfig_ocme);
|
||||
|
||||
// Execute the query
|
||||
const result = await connection.request().query(queryToRun);
|
||||
console.log(`${name} query ran successfully on different server`);
|
||||
|
||||
return result.recordset;
|
||||
} catch (err) {
|
||||
console.log(`Error running ${name} query on different server: ${err}`);
|
||||
|
||||
return [];
|
||||
} finally {
|
||||
// Close the direct connection
|
||||
if (connection) {
|
||||
await connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
51
lstV2/server/services/sqlServer/utils/prodServerConfig.ts
Normal file
51
lstV2/server/services/sqlServer/utils/prodServerConfig.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { settings } from "../../../../database/schema/settings.js";
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
import { serverSettings } from "../../server/controller/settings/getSettings.js";
|
||||
|
||||
export const prodSqlConfig = async () => {
|
||||
try {
|
||||
//const serverSetting = await db.select().from(settings);
|
||||
const serverSetting = serverSettings as any;
|
||||
// create dummy type data
|
||||
const server = serverSetting.filter((s: any) => s.name === "dbServer");
|
||||
const plantToken = serverSetting.filter(
|
||||
(s: any) => s.name === "plantToken"
|
||||
);
|
||||
const dbUser = serverSetting.filter((s: any) => s.name === "dbUser");
|
||||
// if erroring out double check the password was actually encoded before saving
|
||||
const dbPassword = serverSetting.filter(
|
||||
(s: any) => s.name === "dbPass"
|
||||
);
|
||||
|
||||
const sqlConfig = {
|
||||
server: server[0].value,
|
||||
database: `AlplaPROD_${plantToken[0].value}_cus`,
|
||||
user: dbUser[0].value,
|
||||
password: atob(dbPassword[0].value),
|
||||
options: {
|
||||
encrypt: true,
|
||||
trustServerCertificate: true,
|
||||
},
|
||||
requestTimeout: 90000, // in milliseconds
|
||||
pool: {
|
||||
max: 20, // Maximum number of connections in the pool
|
||||
min: 0, // Minimum number of connections in the pool
|
||||
idleTimeoutMillis: 10000, // How long a connection is allowed to be idle before being released
|
||||
reapIntervalMillis: 1000, // how often to check for idle resourses to destory
|
||||
acquireTimeoutMillis: 100000, // How long until a complete timeout happens
|
||||
},
|
||||
};
|
||||
|
||||
return sqlConfig;
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"sqlProd",
|
||||
`${JSON.stringify(
|
||||
error
|
||||
)} "There was an error getting/setting up the config for the prod sql server."`
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user