diff --git a/.env b/.env deleted file mode 100644 index 4e290bf130138564b93ae43e386444b0a8eb0973..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..e9f340212efa30d2d58ba8a99b61411faa1e6e00 --- /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 034999997d203d621a704a911a1502c9cd906fcd..c9ad0865a855760ad19abfa590a32ab47433e1ba 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;