Skip to content

Conversation

@YaroslavKazeev
Copy link

No description provided.

@yunchen4 yunchen4 self-assigned this Sep 5, 2025
Copy link

@yunchen4 yunchen4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Yaroslav,
Overall it is a good assignment. I can see you try to learn more advanced concepts for database. That's good.
There are several points that you need to rework, mainly about the relationship between paper and authors. I also don't see the answers for exercise 4.
Some comments are suggestions. You can choose to apply them or not.
Please let me know once you finish the rework, so I can review it again. Have a nice weekend!

},
];

module.exports = { authors, researchPapers };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: It is good that you separate code and data. Since this JS file is purely for data, you can convert it to JSON files (one for authors, one for research paper) and read these JSON files in the code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed change does not bring any improvements in terms of code clarity and the application's overall volume:
import { readFile } from "fs/promises";
const authors = JSON.parse(
await readFile("./Week2/assignment/authors.json", "utf-8")
);
const researchPapers = JSON.parse(
await readFile("./Week2/assignment/researchPapers.json", "utf-8")
);

You suggest using the code above with the use of the additional package (fs) instead of just this:
import { authors, researchPapers } from "./generateSampleData.js";

Unless there is an unwritten law among developers or a convention regarding data storage and handling, I cannot see why I should use your approach.

Copy link

@yunchen4 yunchen4 Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply said, it is a convention to separate code and pure data.
Using JSON for data can show clearly this is a file about pure data, nothing else. It can help with future maintainability. If I see the JS file I might think: "Well, is there any additional logic in order to generate the data?" So I need to open the file to check. When I see the JSON file I don't need to think about it, it is just data, I can use it anywhere.
JSON also has better compatibility because it can also be used across different platforms and coding languages, but JS doesn't (you need to have JS environment to get data).
In this assignment since it is just for learning purpose, using JS for data is fine, but it is not recommended in real working situations.

Comment on lines 23 to 28
const ALTER_RESEARCH_PAPERS_TABLE = `
ALTER TABLE research_Papers
ADD COLUMN IF NOT EXISTS author_id SMALLINT,
ADD CONSTRAINT fk_author_id
FOREIGN KEY (author_id) REFERENCES authors(author_id) ON DELETE CASCADE
`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs rework: One paper can have several authors. If research_papers table has one column for author and has FK constraints, we cannot use it for several authors.
And also, it is better not to mix the camel case and snake case: research_papers or ResearchPaper.

Comment on lines 105 to 113
const CREATE_AUTHORS_PAPERS_VIEW = `
CREATE OR REPLACE VIEW authors_papers AS
SELECT
a.author_name,
rp.paper_title
FROM
authors a
LEFT JOIN research_papers rp ON a.author_id = rp.author_id
`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs rework: since the relationship between author and paper needs to be changed, you need to rework on this query as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 135 to 136
// Execute the seeding function
seedDatabase();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs rework: I didn't see the answers for exercise 4?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added them in this version

Comment on lines +15 to +18
const CREATE_GENDER_TYPE = `
CREATE TYPE GENDER AS ENUM ('Male', 'Female', 'X');
`;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good that you consider it as enum 👍

Copy link

@yunchen4 yunchen4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I have replied to your comment about why using JSON for data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants