From 93f4456a4da8be5e5c1fe0d68fe4805d1e99e956 Mon Sep 17 00:00:00 2001 From: Amy Fromandi Date: Mon, 23 Sep 2024 14:58:25 -0500 Subject: [PATCH] reverted back to singular credential specs. Refactored it into .env file though. PG Operator generators the connection URI based on a default database so elevation database connection would not work. --- .env | 5 +++++ .gitignore | 1 - v2/larkin.ts | 22 ++++++++++++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 00000000..5fb7ed3c --- /dev/null +++ b/.env @@ -0,0 +1,5 @@ +MACRO_HOST: process.env.host +MACRO_USERNAME: process.env.username +MACRO_PASSWORD: process.env.password +MACRO_DATABASE: process.env.database +CACHE_REFRESH_KEY= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5cd2d286..e7859e51 100755 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ v1/npm-debug.log v1/utilities/scripts/credentials.py .idea venv -.env !v1/credentials.ts v2/utilities/scripts/credentials.py diff --git a/v2/larkin.ts b/v2/larkin.ts index 14dd8cdf..2d29eed9 100644 --- a/v2/larkin.ts +++ b/v2/larkin.ts @@ -17,6 +17,14 @@ const postgresDatabases = { geomacro: "geomacro", elevation: "elevation", }; + +const pgConnection = { + host: process.env.MACRO_HOST, + user: process.env.MACRO_USER, + password: process.env.MACRO_PASSWORD, + database: process.env.MACRO_DATABASE +} + (function () { var larkin = {}; @@ -86,16 +94,18 @@ const postgresDatabases = { "In Macrostrat v2, 'geomacro' is merged with 'burwell' into the 'macrostrat' database.", ); } - let connectionDetails = process.env.MACROSTRAT_DB_URL; + //TODO - PG operator only generates a single connection, so this is not suitable for multiple databases + + let connectionDetails = {...pgConnection}; if (dbName == "elevation") { - /* Special case for elevation database (temporary) */ - connectionDetails = process.env.ELEVATION_DB_URL; + // Special case for elevation database (temporary) + pgConnection.database + connectionDetails.database = 'elevation'; } - const pool = new Pool({ - connectionString: connectionDetails - }); + const pool = new Pool({connectionDetails}); + console.log(connectionDetails) pool.connect(function (err, client, done) { if (err) {