Skip to content

Yana P. - #2

Open
YanaP1312 wants to merge 5 commits into
HackYourAssignment:mainfrom
YanaP1312:main
Open

YanaP1312 wants to merge 5 commits into
HackYourAssignment:mainfrom
YanaP1312:main

Conversation

@YanaP1312

Copy link
Copy Markdown

Implemented Task 1 and Task 2 for the Library Management System module.

Task 1

  • Created PostgreSQL database schema with all required tables and relationships.
  • Added primary keys, foreign keys, constraints, and validation rules.
  • Ensured correct data types, UNIQUE, NOT NULL constraints, and CHECK conditions.

Task 2

  • Added JDBC connection setup and basic application structure.
  • Implemented insertData() using PreparedStatement and RETURNING to fetch generated IDs.
  • Inserted demo data into all tables (publishers, authors, tags, shelves, books, copies, cards, members, borrows, book_authors, book_tags).
  • Implemented fetchData() with a JOIN query to retrieve and display borrow records.
  • Verified successful database interaction and console output.

@composix composix left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work that is not only technically correct, but also done with care and a good eye for detail. The schema is well structured, the table relationships are clear, and the use of keys, constraints, and indexes shows a strong understanding of database design.

Comment thread task-1/docker-compose.yml

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bonus points for this docker compose file. It helps a lot to be able to validate the work in this PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DBeaver is a very good tool choice.

Comment thread task-1/README.MD

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Solid Readme.md.

Comment thread task-1/schema.sql Outdated



-

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This - makes that some tables are missing after running this script due to a syntax error. Deleting the - fixed the problem, so not really a big deal. Running it second time was a bit of a challenge using CREATE TABLE IF NOT EXISTS to make the script a bit more idempotent.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, thank you! Fixed the stray - that was breaking the cards table creation. Also added CREATE TABLE IF NOT EXISTS across the schema so re-running the script won't fail if some tables already exist — makes it more forgiving during testing/debugging.

Comment thread task-1/schema.sql
card_number TEXT UNIQUE NOT NULL,
card_issued_on DATE NOT NULL,
card_expires_on DATE NOT NULL,
CHECK (card_expires_on > card_issued_on)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice date check!

Comment thread task-1/schema.sql Outdated
member_address TEXT NOT NULL,
CONSTRAINT fk_card_id
FOREIGN KEY (card_id)
REFERENCES cards (card_id) ON DELETE CASCADE

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should members whose card is deleted be deleted as well? Or is using ON DELETE SET NULL also an option?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Great question — you're right, CASCADE didn't make sense here. Deleting a member's card (e.g. reissuing a lost one) shouldn't wipe out the member and their borrow history. Switched it to ON DELETE SET NULL, so a member can exist without a card temporarily, and their record (and any borrow history) stays intact.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using a .gitignore file with a line "target/" could be helpful to prevent build output to end up under version control.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added target/ (and *.class, plus out/ for IntelliJ's non-Maven build output) to .gitignore. Also removed target/ from version control since it had already been committed. Thanks for flagging it!

…DELETE SET NULL; update .gitignore for target/ and *.class
@YanaP1312

Copy link
Copy Markdown
Author

@composix , thank you so much for the thorough review and the kind words — really appreciate you taking the time to go through the schema in detail! Learned a lot from these — especially the point about cascade semantics, that one made me think more carefully about what "deleting" actually means for each relationship in the schema.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants