Skip to content
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

Fix course identifiers #19

Merged
merged 6 commits into from
Mar 13, 2024
Merged

Conversation

marianysilva
Copy link
Contributor

@marianysilva marianysilva commented Mar 6, 2024

Description

  • Add Course ID GENERATED ALWAYS AS IDENTITY
  • Rename id params to `courseUUID``
  • Improve Course SQL queries
  • Remove Update By Code

Type of change

  • 🐞 Bugfix (fixes an issue)
  • 🆕 New feature (adds functionality)
  • 🚀 Code Enhancement (improve code quality)
  • 🖌️ UI Improvement (improves UI/UX experience)
  • ⏺️ Migration (schema update and/or data migration)
  • ⚙️ Dependency Update (dependencies have been updated)
  • 🗃 Documentation Update (adds/updates the documentation)

How Has This Been Tested?

  • go mod vendor
  • go get ./...
  • make test
  • make migration-up
  • make migration-down

Summary by CodeRabbit

  • New Features
    • Enhanced the courses database schema for better integrity and efficiency.
  • Refactor
    • Improved SQL query structure and naming conventions for course operations.
    • Shifted from using integer IDs to UUIDs for course identification across the application.
  • Bug Fixes
    • Fixed unique constraint issues by adjusting the courses table structure.
  • Documentation
    • Updated internal documentation to reflect changes in parameter naming and method signatures.

Copy link

coderabbitai bot commented Mar 6, 2024

Walkthrough

Walkthrough

The updates focus on enhancing the database structure and codebase for course management. The primary key for the courses table now uses an integer type with IDENTITY, and the code column's uniqueness is handled via a new index alongside deleted_at. Code refactoring includes clearer naming, improved SQL query structure, and a shift from integer IDs to UUIDs for course identification, affecting both the domain logic and database interactions.

Changes

File(s) Summary
db/migrations/...create_courses_table.up.sql Altered primary key to integer with IDENTITY, modified code column, added unique index on code and deleted_at, and commented on deleted_at.
internal/course/database/course_queries.go
internal/course/database/course_repository.go
internal/course/database/course_repository_test.go
internal/course/domain/course.go
internal/course/domain/course_repository.go
internal/course/domain/course_service.go
Refactored SQL queries, updated method names and parameters for UUID usage, removed ID field from Course struct, and improved readability and consistency across the board.

🐇✨

A hop, a skip, in the database we dip,
With keys and codes, our structure flips.
Through fields and queries, our journey's neat,
With UUIDs now, our courses greet.
A change so grand, with logic so bright,
Here's to the code, that's now just right.
🌟📚

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 347c872 and de73f4f.
Files selected for processing (7)
  • db/migrations/1657379568_create_courses_table.up.sql (2 hunks)
  • internal/course/database/course_queries.go (1 hunks)
  • internal/course/database/course_repository.go (3 hunks)
  • internal/course/database/course_repository_test.go (9 hunks)
  • internal/course/domain/course.go (1 hunks)
  • internal/course/domain/course_repository.go (1 hunks)
  • internal/course/domain/course_service.go (2 hunks)
Additional comments: 17
internal/course/domain/course_repository.go (3)
  • 6-6: Renaming the parameter to courseUUID in the Course method aligns with the PR's objective of using UUIDs for course identification. This change enhances clarity and consistency across the codebase.
  • 9-9: The introduction of UpdateCourseByUUID method in place of UpdateCourseByID and UpdateCourseByCode is a positive change. It simplifies the update mechanism and enforces updates through a more consistent identifier, which is in line with the PR objectives.
  • 10-10: Changing the parameter to courseUUID in the DeleteCourse method is consistent with the shift towards using UUIDs for course identification. This change ensures consistency and clarity in the method signature.
internal/course/domain/course.go (1)
  • 11-20: Removing the ID field from the Course struct and adjusting the field order to start with UUID is a significant change that aligns with the PR's objective of using UUIDs for course identification. This modification simplifies the identification mechanism and enhances data integrity.
db/migrations/1657379568_create_courses_table.up.sql (3)
  • 5-5: Changing the primary key definition to use an integer type with an IDENTITY property instead of bigserial is a good practice for automating the generation of unique identifiers. This change aligns with modern database design practices and enhances data integrity.
  • 7-7: Modifying the code column to no longer be UNIQUE directly in the column definition and instead using a unique index on code and deleted_at columns supports the implementation of soft deletion patterns. This approach allows for the reuse of course codes while maintaining uniqueness among active records.
  • 19-20: Adding a comment to the deleted_at column to explain its purpose for enabling soft deletes is a good practice for code readability and maintainability. It helps future developers understand the design decisions made in the database schema.
internal/course/domain/course_service.go (3)
  • 10-11: Renaming the parameter to courseUUID in the Course function is consistent with the overall PR objectives and enhances clarity in the method signature. This change ensures consistency across the codebase.
  • 37-37: Refactoring the UpdateCourse function to directly use UpdateCourseByUUID simplifies the update mechanism and aligns with the shift towards using UUIDs for course identification. This change improves the maintainability of the code.
  • 43-44: Changing the parameter to courseUUID in the DeleteCourse function aligns with the PR's objective and enhances consistency in method signatures across the codebase.
internal/course/database/course_queries.go (2)
  • 8-17: Adding a constant for returning columns and updating query constants for clarity and consistency is a good practice. It enhances the readability and maintainability of the SQL queries within the codebase.
  • 22-36: Refactoring the SQL queries to include returning columns specification and improving the formatting of the queries significantly enhances readability and maintainability. Specifying returning columns is a best practice that ensures only necessary data is retrieved, which can improve performance.
internal/course/database/course_repository.go (3)
  • 39-47: Changing the parameter name from id to courseUUID in the Course method is consistent with the PR objectives and enhances clarity in the method signature. This change ensures consistency across the codebase.
  • 89-91: Renaming UpdateCourseByID to UpdateCourseByUUID and updating the SQL statement accordingly aligns with the shift towards using UUIDs for course identification. This change simplifies the update mechanism and enhances data integrity.
  • 114-121: Changing the parameter name from id to courseUUID in the DeleteCourse method ensures consistency with the use of UUIDs across the codebase. This change enhances clarity and maintainability of the code.
internal/course/database/course_repository_test.go (2)
  • 35-38: Adjusting the test data to reflect the use of UUIDs instead of integer IDs is necessary to align with the changes made in the codebase. This ensures that the tests accurately represent the current state of the code and its functionality.
  • 208-212: Renaming functions related to updating courses by ID to use UUID instead and adjusting the test data accordingly reflects the shift towards using UUIDs for course identification. This change ensures that the tests remain relevant and accurate.

@marianysilva marianysilva force-pushed the fix-course-identifiers branch from de73f4f to 5109117 Compare March 6, 2024 21:51
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 347c872 and 5109117.
Files selected for processing (7)
  • db/migrations/1657379568_create_courses_table.up.sql (2 hunks)
  • internal/course/database/course_queries.go (1 hunks)
  • internal/course/database/course_repository.go (3 hunks)
  • internal/course/database/course_repository_test.go (9 hunks)
  • internal/course/domain/course.go (1 hunks)
  • internal/course/domain/course_repository.go (1 hunks)
  • internal/course/domain/course_service.go (2 hunks)
Files skipped from review as they are similar to previous changes (7)
  • db/migrations/1657379568_create_courses_table.up.sql
  • internal/course/database/course_queries.go
  • internal/course/database/course_repository.go
  • internal/course/database/course_repository_test.go
  • internal/course/domain/course.go
  • internal/course/domain/course_repository.go
  • internal/course/domain/course_service.go

@marianysilva marianysilva force-pushed the fix-course-identifiers branch from 5109117 to 54362b2 Compare March 6, 2024 21:56
@codecov-commenter
Copy link

codecov-commenter commented Mar 6, 2024

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 46.46%. Comparing base (347c872) to head (c04e66a).

Files Patch % Lines
internal/course/database/course_repository.go 66.66% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #19      +/-   ##
==========================================
+ Coverage   43.58%   46.46%   +2.88%     
==========================================
  Files           9        9              
  Lines         413      396      -17     
==========================================
+ Hits          180      184       +4     
+ Misses        211      190      -21     
  Partials       22       22              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

internal/course/database/course_queries.go Outdated Show resolved Hide resolved
internal/course/database/course_queries.go Outdated Show resolved Hide resolved
internal/course/database/course_repository.go Outdated Show resolved Hide resolved
internal/course/database/course_repository_test.go Outdated Show resolved Hide resolved
internal/course/domain/course.go Outdated Show resolved Hide resolved
internal/course/domain/course_repository.go Outdated Show resolved Hide resolved
internal/course/domain/course_service.go Outdated Show resolved Hide resolved
@marianysilva marianysilva requested a review from rluders March 7, 2024 23:14
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 347c872 and 6244cbf.
Files selected for processing (7)
  • db/migrations/1657379568_create_courses_table.up.sql (2 hunks)
  • internal/course/database/course_queries.go (1 hunks)
  • internal/course/database/course_repository.go (3 hunks)
  • internal/course/database/course_repository_test.go (9 hunks)
  • internal/course/domain/course.go (1 hunks)
  • internal/course/domain/course_repository.go (1 hunks)
  • internal/course/domain/course_service.go (2 hunks)
Files skipped from review as they are similar to previous changes (7)
  • db/migrations/1657379568_create_courses_table.up.sql
  • internal/course/database/course_queries.go
  • internal/course/database/course_repository.go
  • internal/course/database/course_repository_test.go
  • internal/course/domain/course.go
  • internal/course/domain/course_repository.go
  • internal/course/domain/course_service.go

@marianysilva marianysilva force-pushed the fix-course-identifiers branch from 6244cbf to d2b2ad1 Compare March 7, 2024 23:33
@marianysilva marianysilva force-pushed the fix-course-identifiers branch from d2b2ad1 to 8fbcd7a Compare March 7, 2024 23:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 347c872 and 8fbcd7a.
Files selected for processing (7)
  • db/migrations/1657379568_create_courses_table.up.sql (2 hunks)
  • internal/course/database/course_queries.go (1 hunks)
  • internal/course/database/course_repository.go (3 hunks)
  • internal/course/database/course_repository_test.go (9 hunks)
  • internal/course/domain/course.go (1 hunks)
  • internal/course/domain/course_repository.go (1 hunks)
  • internal/course/domain/course_service.go (2 hunks)
Files skipped from review as they are similar to previous changes (7)
  • db/migrations/1657379568_create_courses_table.up.sql
  • internal/course/database/course_queries.go
  • internal/course/database/course_repository.go
  • internal/course/database/course_repository_test.go
  • internal/course/domain/course.go
  • internal/course/domain/course_repository.go
  • internal/course/domain/course_service.go

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8fbcd7a and c04e66a.
Files selected for processing (1)
  • db/migrations/1657379568_create_courses_table.up.sql (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • db/migrations/1657379568_create_courses_table.up.sql

Copy link
Contributor

@rluders rluders left a comment

Choose a reason for hiding this comment

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

lgtm

@rluders
Copy link
Contributor

rluders commented Mar 13, 2024

@arianerocha since you where involved in the discussions, I'll wait for your approval before squash and merge. :)

@rluders rluders merged commit 46a9d76 into sumelms:main Mar 13, 2024
1 check passed
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.

4 participants