From 75b46974a2bddaf65d0c0b756fe5b0b39fee4660 Mon Sep 17 00:00:00 2001 From: Vinod Bangera <vinodbangera@niveussolutions.com> Date: Wed, 19 Feb 2025 09:46:41 +0530 Subject: [PATCH] added gitignore and table creation --- .env | 6 ------ .gitignore | 28 ++++++++++++++++++++++++++++ config/db.js | 24 ++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 8 deletions(-) delete mode 100644 .env create mode 100644 .gitignore diff --git a/.env b/.env deleted file mode 100644 index 4e290bf..0000000 --- a/.env +++ /dev/null @@ -1,6 +0,0 @@ -PORT=5000 -DB_USER=postgres -DB_HOST=127.0.0.1 -DB_NAME=my_pgdb -DB_PASSWORD=Adarsh@2002 -DB_PORT=5432 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e9f3402 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# Node.js +node_modules/ +npm-debug.log +yarn-error.log + +# Environment variables +.env + +# Logs +logs/ +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Database +*.sqlite +*.sqlite3 + +# IDEs and editors +.vscode/ +.idea/ +*.sublime-project +*.sublime-workspace + +# Operating system files +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/config/db.js b/config/db.js index 0349999..c9ad086 100644 --- a/config/db.js +++ b/config/db.js @@ -10,7 +10,27 @@ const pool = new Pool({ }); pool.connect() - .then(() => console.log(" PostgreSQL Database Connected Successfully")) - .catch((err) => console.error(" Database Connection Failed:", err)); + .then(async (client) => { + console.log("PostgreSQL Database Connected Successfully"); + + const createTableQuery = ` + CREATE TABLE IF NOT EXISTS usage_metrics ( + id SERIAL PRIMARY KEY, + email VARCHAR(255) NOT NULL, + projectId VARCHAR(255) NOT NULL, + requestType VARCHAR(50) CHECK (requestType IN ('completion', 'explanation', 'documentation', 'testcase')), + linesOfCodeSuggested INT DEFAULT 0, + linesOfCodeAccepted INT DEFAULT 0, + requestId UUID DEFAULT gen_random_uuid(), + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ); + `; + + await client.query(createTableQuery); + console.log("Table 'usage_metrics' is ready"); + + client.release(); + }) + .catch((err) => console.error("Database Connection Failed:", err)); module.exports = pool; -- GitLab