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: substring table name #111

Merged
merged 1 commit into from
Jan 27, 2024
Merged

fix: substring table name #111

merged 1 commit into from
Jan 27, 2024

Conversation

kazumatsudo
Copy link
Owner

@kazumatsudo kazumatsudo commented Jan 27, 2024

Summary by CodeRabbit

  • Refactor
    • Improved the SQL sentence creation process by ensuring table names do not exceed 64 characters.
  • Tests
    • Added tests to verify the truncation of table names in SQL sentence creation.

@kazumatsudo kazumatsudo self-assigned this Jan 27, 2024
Copy link

coderabbitai bot commented Jan 27, 2024

Walkthrough

The recent update introduces a refinement to the TableName case class, enhancing its functionality by incorporating a method to ensure the table name does not exceed 64 characters in length when converted to an SQL sentence. This change, aimed at maintaining compliance with common database naming constraints, includes the addition of a private method to enforce the maximum length and an adjustment to the toSqlSentence method. Corresponding tests have been added to validate this new behavior effectively.

Changes

File Path Change Summary
.../table/ddl/TableName.scala Added a maxLength method and updated toSqlSentence to truncate value to 64 characters max.
.../table/ddl/TableNameSpec.scala Added tests for toSqlSentence method, verifying table name truncation to 64 characters.

🐇✨
In the realm of code, where tables are named,
A rabbit hopped, its purpose proclaimed.
"No name too long," it cheerily stated,
Ensuring SQL's grace is never abated.
🌟🐾

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.
  • 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 from git 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.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (82da7e0) 73.90% compared to head (28400b8) 74.10%.
Report is 1 commits behind head on main.

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
+ Coverage   73.90%   74.10%   +0.20%     
==========================================
  Files          20       20              
  Lines         387      390       +3     
  Branches       37       30       -7     
==========================================
+ Hits          286      289       +3     
  Misses        101      101              

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

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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0221708 and 28400b8.
Files selected for processing (2)
  • src/main/scala/domain/table/ddl/TableName.scala (1 hunks)
  • src/test/scala/domain/table/ddl/TableNameSpec.scala (1 hunks)

@@ -1,5 +1,10 @@
package domain.table.ddl

case class TableName(private val value: String) extends AnyVal {
def toSqlSentence: String = value
private def maxLength = 64
Copy link

Choose a reason for hiding this comment

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

The maxLength method is defined as a def which means it gets evaluated every time it's accessed. For constants like maxLength, it's more efficient to use val instead of def.

- private def maxLength = 64
+ private val maxLength = 64

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
private def maxLength = 64
private val maxLength = 64

Comment on lines +6 to +9
def toSqlSentence: String = if (value.length > maxLength) {
value.substring(0, maxLength)
} else
value
Copy link

Choose a reason for hiding this comment

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

The logic for truncating the value string to a maximum length of 64 characters is correctly implemented. However, consider encapsulating the truncation logic within a separate method for better readability and potential reuse.

def toSqlSentence: String = truncateToMaxLength(value)

private def truncateToMaxLength(value: String): String = 
  if (value.length > maxLength) value.substring(0, maxLength) else value

Comment on lines +13 to +18
it(
"if the length is 64 or more, return the truncated one after 65 truncated"
) {
val tableName = "a" * 65
TableName(tableName).toSqlSentence shouldBe tableName.substring(0, 64)
}
Copy link

Choose a reason for hiding this comment

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

The test description "if the length is 64 or more, return the truncated one after 65 truncated" is somewhat confusing. It would be clearer if it stated "if the length is more than 64, return the truncated string to 64 characters."

Consider rephrasing the test description for clarity:

- "if the length is 64 or more, return the truncated one after 65 truncated"
+ "if the length exceeds 64 characters, it should be truncated to 64 characters"

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
it(
"if the length is 64 or more, return the truncated one after 65 truncated"
) {
val tableName = "a" * 65
TableName(tableName).toSqlSentence shouldBe tableName.substring(0, 64)
}
it(
"if the length exceeds 64 characters, it should be truncated to 64 characters"
) {
val tableName = "a" * 65
TableName(tableName).toSqlSentence shouldBe tableName.substring(0, 64)
}

@kazumatsudo kazumatsudo merged commit 11679e7 into main Jan 27, 2024
1 check passed
@kazumatsudo kazumatsudo deleted the fix/substring_table_name branch January 27, 2024 03:14
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.

None yet

2 participants