Skip to content

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Feb 1, 2025

📑 Description

Summary by CodeRabbit

  • New Features

    • Enhanced database schema building with native support for boolean and customizable column types, offering more flexible and precise schema definitions.
  • Behavior Improvements

    • Refined logging defaults for more consistent and appropriate runtime messaging across environments.
  • Chores

    • Upgraded the product version to v1.15.3 and updated several dependencies to boost performance and overall stability.

✅ Checks

  • Added test cases for my code

@hwbrzzl hwbrzzl requested a review from a team as a code owner February 1, 2025 14:31
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 1, 2025

Walkthrough

The pull request makes several changes across multiple components. It improves test reliability by using a single timestamp for time-related assertions, extends the database schema functionality by adding new methods (Boolean and Column in Blueprint and TypeBoolean in Grammar) along with their corresponding mocks, and updates schema tests to verify new column definitions. The logger behavior is slightly altered by removing an environment-specific conditional. Additionally, the PR includes modifications to column type resolution logic in utility functions, dependency version bumps, and a version constant update.

Changes

Files Change Summary
auth/auth_test.go Updated test cases to use a local now variable for both ExpireAt and IssuedAt to ensure consistent timestamp calculations.
contracts/database/schema/blueprint.go
database/schema/blueprint.go
mocks/database/schema/Blueprint.go
Added new methods (Boolean and Column) to the Blueprint interface/struct and corresponding mocks, enabling the creation of boolean and custom type columns.
contracts/database/schema/grammar.go
mocks/database/schema/Grammar.go
Introduced a new TypeBoolean method to the Grammar interface and its mock, allowing for boolean column definition handling.
database/gorm/logger.go Removed the conditional check for the Artisan environment that previously set the logging level to Error, simplifying logging behavior.
database/schema/utils.go
database/schema/utils_test.go
Modified the ColumnType function to return column.GetType() instead of an empty string when a method is invalid, and updated the tests to expect this behavior.
support/constant.go
tests/go.mod
Updated the version constant from "v1.15.2" to "v1.15.3" and bumped dependency versions for gofakeit, lo, and golang.org/x/exp in the tests.
tests/schema_test.go Enhanced schema tests by introducing new boolean_default and custom_type columns with updated assertions, including revised expectations for the total number of columns.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Blueprint
    participant createAndAddColumn
    Caller->>Blueprint: Call Boolean(column)
    Blueprint->>createAndAddColumn: Create boolean column
    createAndAddColumn-->>Blueprint: Return ColumnDefinition
    Blueprint-->>Caller: Provide ColumnDefinition
Loading
sequenceDiagram
    participant Caller
    participant Grammar
    Caller->>Grammar: Call TypeBoolean(ColumnDefinition)
    Grammar-->>Caller: Return type string for boolean column
Loading

Possibly related PRs

  • feat: [#280] Add Time methods #733: Focuses on time-related test improvements and introduces new time-related methods in the Blueprint interface, showing a connection in handling time functionalities.

Suggested reviewers

  • devhaozi
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • Generate unit testing code 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Feb 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.16%. Comparing base (9826b37) to head (d5bf5ed).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #842      +/-   ##
==========================================
+ Coverage   67.12%   67.16%   +0.03%     
==========================================
  Files         150      150              
  Lines       10442    10442              
==========================================
+ Hits         7009     7013       +4     
+ Misses       3058     3055       -3     
+ Partials      375      374       -1     

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

Copy link
Contributor

@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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
database/schema/blueprint.go (1)

85-87: Consider adding type validation.

The Column method provides flexibility for creating columns of any type, but it might benefit from validation to ensure only supported types are used.

Consider adding type validation:

 func (r *Blueprint) Column(column, ttype string) schema.ColumnDefinition {
+    validTypes := map[string]bool{
+        "bigInteger": true, "boolean": true, "char": true,
+        "date": true, "dateTime": true, "decimal": true,
+        "double": true, "enum": true, "float": true,
+        "integer": true, "json": true, "jsonb": true,
+        "longText": true, "mediumInteger": true, "mediumText": true,
+        "smallInteger": true, "string": true, "text": true,
+        "time": true, "timestamp": true, "tinyInteger": true,
+        "tinyText": true,
+    }
+    if !validTypes[ttype] {
+        panic(fmt.Sprintf("Unsupported column type: %s", ttype))
+    }
     return r.createAndAddColumn(ttype, column)
 }
database/schema/blueprint_test.go (1)

110-117: Consider adding more test cases.

While the basic test case is good, consider adding tests for:

  1. Column modifiers (e.g., nullable, default value)
  2. Column changes using Change()
  3. Error cases

Example additional test cases:

 func (s *BlueprintTestSuite) TestBoolean() {
     name := "name"
     s.blueprint.Boolean(name)
     s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{
         name:  &name,
         ttype: convert.Pointer("boolean"),
     })
+
+    // Test with nullable modifier
+    s.blueprint.Boolean(name).Nullable()
+    s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{
+        name:     &name,
+        ttype:    convert.Pointer("boolean"),
+        nullable: convert.Pointer(true),
+    })
+
+    // Test with default value
+    s.blueprint.Boolean(name).Default(true)
+    s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{
+        name:  &name,
+        ttype: convert.Pointer("boolean"),
+        def:   convert.Pointer(true),
+    })
+
+    // Test with Change modifier
+    s.blueprint.Boolean(name).Change()
+    s.Contains(s.blueprint.GetAddedColumns(), &ColumnDefinition{
+        name:   &name,
+        ttype:  convert.Pointer("boolean"),
+        change: true,
+    })
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9826b37 and d5bf5ed.

⛔ Files ignored due to path filters (1)
  • tests/go.sum is excluded by !**/*.sum
📒 Files selected for processing (13)
  • auth/auth_test.go (2 hunks)
  • contracts/database/schema/blueprint.go (1 hunks)
  • contracts/database/schema/grammar.go (1 hunks)
  • database/gorm/logger.go (0 hunks)
  • database/schema/blueprint.go (2 hunks)
  • database/schema/blueprint_test.go (1 hunks)
  • database/schema/utils.go (1 hunks)
  • database/schema/utils_test.go (1 hunks)
  • mocks/database/schema/Blueprint.go (2 hunks)
  • mocks/database/schema/Grammar.go (1 hunks)
  • support/constant.go (1 hunks)
  • tests/go.mod (2 hunks)
  • tests/schema_test.go (11 hunks)
💤 Files with no reviewable changes (1)
  • database/gorm/logger.go
✅ Files skipped from review due to trivial changes (3)
  • auth/auth_test.go
  • support/constant.go
  • tests/go.mod
🧰 Additional context used
🪛 golangci-lint (1.62.2)
tests/schema_test.go

175-175: table.Boolean undefined (type "github.com/goravel/framework/contracts/database/schema".Blueprint has no field or method Boolean)

(typecheck)


2506-2506: table.Boolean undefined (type "github.com/goravel/framework/contracts/database/schema".Blueprint has no field or method Boolean)

(typecheck)


2509-2509: table.Column undefined (type "github.com/goravel/framework/contracts/database/schema".Blueprint has no field or method Column)

(typecheck)


2511-2511: table.Column undefined (type "github.com/goravel/framework/contracts/database/schema".Blueprint has no field or method Column)

(typecheck)

⏰ Context from checks skipped due to timeout of 300000ms (1)
  • GitHub Check: test / windows (1.23)
🔇 Additional comments (13)
contracts/database/schema/grammar.go (1)

66-67: LGTM! Well-structured interface addition.

The new TypeBoolean method follows the established pattern of other type methods in the interface, maintaining consistency in the API design.

contracts/database/schema/blueprint.go (2)

12-13: LGTM! Well-structured Boolean method addition.

The new Boolean method follows the established pattern of other column definition methods in the interface.


18-19: LGTM! Well-structured Column method addition.

The new Column method provides flexibility for custom column types while maintaining consistency with the interface design.

database/schema/utils.go (1)

42-42: LGTM! Improved error handling.

The change to return column.GetType() instead of an empty string preserves valuable type information when a method is not found, making it easier to debug issues with invalid column types.

database/schema/utils_test.go (1)

40-40: LGTM! Test updates match implementation changes.

The test changes correctly reflect the new behavior where:

  1. GetType() is called twice due to the implementation change
  2. The assertion now expects the actual type ("invalid") instead of an empty string

Also applies to: 44-44

database/schema/blueprint.go (1)

59-61: LGTM! The Boolean method follows the established pattern.

The implementation correctly uses the createAndAddColumn function and follows the same pattern as other type methods in the file.

mocks/database/schema/Grammar.go (1)

1501-1545: LGTM! The mock implementation follows the established pattern.

The TypeBoolean mock method is correctly implemented with all necessary mock functionality, following the same pattern as other type methods in the file.

tests/schema_test.go (3)

175-175: LGTM! Boolean column type implementation is consistent across databases.

The boolean column type implementation is correctly tested across different databases with appropriate type mappings:

  • Postgres: boolean/bool
  • SQLite: tinyint(1)
  • MySQL: tinyint(1)
  • SQL Server: bit

The default value handling is also consistent:

  • Postgres: 'true'
  • SQLite: '1'
  • MySQL: '1'
  • SQL Server: '('1')'

Also applies to: 289-297, 628-635, 928-936, 1260-1268

🧰 Tools
🪛 golangci-lint (1.62.2)

175-175: table.Boolean undefined (type "github.com/goravel/framework/contracts/database/schema".Blueprint has no field or method Boolean)

(typecheck)


2508-2512: LGTM! Custom type column implementation handles database-specific types correctly.

The implementation correctly handles database-specific custom types:

  • Postgres: Uses 'macaddr' type
  • Other databases: Uses 'geometry' type

The conditional type selection ensures compatibility across different databases.

Also applies to: 316-323, 652-659, 955-962, 1287-1294

🧰 Tools
🪛 golangci-lint (1.62.2)

2509-2509: table.Column undefined (type "github.com/goravel/framework/contracts/database/schema".Blueprint has no field or method Column)

(typecheck)


2511-2511: table.Column undefined (type "github.com/goravel/framework/contracts/database/schema".Blueprint has no field or method Column)

(typecheck)


2552-2552: LGTM! Column count updated to include new columns.

The test correctly verifies the expected number of columns (35) after adding boolean_default and custom_type columns.

mocks/database/schema/Blueprint.go (3)

120-166: LGTM! Boolean method mock implementation follows established patterns.

The Boolean method mock is correctly implemented with:

  • Proper error handling for unspecified return values
  • Type-safe method shadowing
  • Helper methods for defining expectations

278-325: LGTM! Column method mock implementation follows established patterns.

The Column method mock is correctly implemented with:

  • Proper error handling for unspecified return values
  • Type-safe method shadowing
  • Helper methods for defining expectations

Line range hint 1-1: Verify Blueprint interface compatibility.

The static analysis hints indicate that the Blueprint interface may be missing the Boolean and Column method declarations.

Run the following script to verify the interface declarations:

✅ Verification successful

Blueprint interface compatibility verified.

The shell output confirms that both the Boolean and Column methods exist as implemented on the mock type, ensuring compatibility with the Blueprint interface.

  • The Boolean method is implemented (see func (_m *Blueprint) Boolean(... and its expecter counterpart).
  • The Column method is implemented (see func (_m *Blueprint) Column(... along with its expecter version).
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if Blueprint interface declares the Boolean and Column methods

# Search for Blueprint interface declaration and its methods
ast-grep --pattern $'interface Blueprint {
  $$$
  Boolean(column string) ColumnDefinition
  $$$
}'

ast-grep --pattern $'interface Blueprint {
  $$$
  Column(column string, ttype string) ColumnDefinition
  $$$
}'

Length of output: 214


Script:

#!/bin/bash
echo "Extracting the Blueprint interface block from mocks/database/schema/Blueprint.go ..."
sed -n '/interface Blueprint {/,/}/p' mocks/database/schema/Blueprint.go

echo "-----------------------"
echo "Searching for 'Boolean' method declarations in mocks/database/schema/Blueprint.go ..."
rg "Boolean\s*\(" mocks/database/schema/Blueprint.go

echo "-----------------------"
echo "Searching for 'Column' method declarations in mocks/database/schema/Blueprint.go ..."
rg "Column\s*\(" mocks/database/schema/Blueprint.go

Length of output: 1327

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants