-
Notifications
You must be signed in to change notification settings - Fork 8
switch to Postgres database #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for excel-data-analytics ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates history storage and retrieval from a local Express/MongoDB setup to PostgreSQL via Netlify Functions.
- Replace Mongoose model and Express server with pg Pool and serverless-http-wrapped Express app under Netlify Functions.
- Update client endpoints to call Netlify Function routes and switch identifiers from _id to id.
- Add Netlify configuration and a bootstrap DB script that ensures the file_history table exists.
Reviewed Changes
Copilot reviewed 11 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pages/History.jsx | Point history fetch/delete to Netlify Functions; switch key usage from _id to id. |
| src/components/excel/ExcelUploader.jsx | Post history entries to Netlify Function (path updated). |
| server/routes/history.js | Replace Mongoose queries with PostgreSQL queries via pg Pool. |
| server/db.js | Initialize pg Pool and ensure file_history table exists. |
| server/api.js | Create serverless Express function and mount history routes. |
| server/package.json | Add server-side dependencies for functions runtime. |
| package.json | Swap Mongo/Mongoose for pg and serverless-http at the root. |
| netlify.toml | Configure Netlify Functions directory and plugin. |
| server/models/fileHistory.model.js | Remove Mongoose model (no longer used). |
| server/index.js | Remove standalone Express server (replaced by Netlify Function). |
| server/hello.js | Add sample Netlify Function. |
Files not reviewed (2)
- pnpm-lock.yaml: Language not supported
- server/package-lock.json: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| }; | ||
|
|
||
| await axios.post('http://localhost:5000/history/add', historyData); | ||
| await axios.post('/.netlify/functions/history/add', historyData); |
Copilot
AI
Oct 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Netlify Function entry point is server/api.js, so the correct endpoint prefix is "/.netlify/functions/api". This call will 404 as written. Update the URL to "/.netlify/functions/api/history/add".
| await axios.post('/.netlify/functions/history/add', historyData); | |
| await axios.post('/.netlify/functions/api/history/add', historyData); |
| try { | ||
| const history = await FileHistory.find({ user: req.query.user }); | ||
| res.json(history); | ||
| const { rows } = await pool.query('SELECT * FROM file_history WHERE "user" = $1 ORDER BY uploadDate DESC', [req.query.user]); |
Copilot
AI
Oct 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning raw PostgreSQL column names will break the existing client, which references fileName and uploadDate (camelCase). Alias the columns in the SELECT to preserve the API contract and order by the actual column name (uploaddate) to avoid relying on aliases in ORDER BY.
Suggested change:
const { rows } = await pool.query(
'SELECT id, filename AS "fileName", uploaddate AS "uploadDate", size, "user" FROM file_history WHERE "user" = $1 ORDER BY uploaddate DESC',
[req.query.user]
);
| const { rows } = await pool.query('SELECT * FROM file_history WHERE "user" = $1 ORDER BY uploadDate DESC', [req.query.user]); | |
| const { rows } = await pool.query( | |
| 'SELECT id, filename AS "fileName", uploaddate AS "uploadDate", size, "user" FROM file_history WHERE "user" = $1 ORDER BY uploaddate DESC', | |
| [req.query.user] | |
| ); |
| <td className="px-5 py-5 border-b border-gray-200 bg-white text-sm"> | ||
| <p className="text-gray-900 whitespace-no-wrap">{item.fileName}</p> | ||
| </td> |
Copilot
AI
Oct 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the switch to PostgreSQL, the returned row keys will be lowercase (filename/uploaddate) unless aliased. Either update this reference to item.filename, or adopt the server-side aliasing in server/routes/history.js (see prior comment) to keep item.fileName working.
| "dependencies": { | ||
| "pg": "^8.12.0", | ||
| "dotenv": "^17.0.0", | ||
| "express": "^5.1.0" |
Copilot
AI
Oct 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
server/api.js requires serverless-http, but it's not declared in server/package.json. Since the functions directory is set to "server", declare serverless-http here to avoid module resolution issues during Netlify Functions build/runtime.
| "express": "^5.1.0" | |
| "express": "^5.1.0", | |
| "serverless-http": "^3.0.0" |
No description provided.