Skip to content

fix: [#589] Context in PrepareForValidation always nil #917

Merged
hwbrzzl merged 2 commits intov1.15.xfrom
bowen/#589
Feb 28, 2025
Merged

fix: [#589] Context in PrepareForValidation always nil #917
hwbrzzl merged 2 commits intov1.15.xfrom
bowen/#589

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Feb 27, 2025

📑 Description

Closes goravel/goravel#589

Summary by CodeRabbit

  • New Features

    • Added enhanced support for boolean column types in database schemas across multiple database engines.
    • Introduced context handling improvements for validation functions.
  • Refactoring

    • Centralized service binding references for a more unified dependency management.
    • Streamlined internal structures and standardized naming conventions.
    • Updated logging and CLI output for clarity.
  • Tests

    • Expanded test coverage with additional scenarios and improved mock implementations.
  • Chores

    • Upgraded the Go version and various external dependencies for improved performance and compatibility.

✅ Checks

  • Added test cases for my code

Copilot AI review requested due to automatic review settings February 27, 2025 09:39
@hwbrzzl hwbrzzl requested a review from a team as a code owner February 27, 2025 09:39
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request makes widespread updates across the codebase. In tests, repeated timestamp calls have been streamlined for consistency. Multiple service provider files now remove local binding constants in favor of centralized identifiers from the contracts package, and receiver variable names have been updated for clarity. The console application’s constructor has been updated with an additional boolean flag for artisan mode. In the database layer, new methods and tests have been added for boolean and custom column types, with corresponding changes in schema grammars for several database drivers. Additionally, contracts and mocks have been extended, validation functions now accept a context parameter, and dependency versions have been updated in go.mod.

Changes

File(s) Change Summary
auth/auth_test.go Replaced multiple carbon.Now() calls with a single variable for consistent timestamp usage in test methods.
Service Providers & Container Files
(e.g. auth/service_provider.go, cache/service_provider.go, config/service_provider.go, console/service_provider.go, crypt/service_provider.go, event/service_provider.go, filesystem/service_provider.go, grpc/service_provider.go, hash/service_provider.go, mail/service_provider.go, queue/service_provider.go, route/service_provider.go, schedule/service_provider.go, session/service_provider.go, testing/service_provider.go, translation/service_provider.go, validation/service_provider.go, foundation/container.go, foundation/application_test.go, http/service_provider.go, log/service_provider.go)
Removed local binding constants (e.g. "goravel.xxx") and updated method receivers to use contracts.Binding* constants; renamed receivers for clarity and consistency in dependency registration.
console/application.go,
console/application_test.go,
console/cli_helper_test.go
Updated NewApplication signature to include a new boolean parameter (e.g. useArtisan), with corresponding test updates to reflect artisan mode configuration.
Database ORM, Schema & Grammar Changes
(e.g. database/gorm/logger.go, database/orm/orm.go, database/schema/blueprint.go, database/schema/blueprint_test.go, database/schema/grammars/{mysql,postgres,sqlite,sqlserver,utils}.go, database/schema/*_test.go, database/schema/schema.go, database/seeder/seeder.go, database/service_provider.go)
Added new boolean and generic column methods in the Blueprint and Grammar interfaces; updated type mappings for boolean columns across MySQL, Postgres, SQLite, and SQL Server; refined related tests and removed deprecated binding constants; integrated HTTP context handling in ORM.
Contracts & Mocks
(e.g. contracts/binding.go,
contracts/database/schema/blueprint.go,
contracts/database/schema/grammar.go,
mocks/database/schema/Blueprint.go,
mocks/database/schema/Grammar.go)
Introduced a centralized set of binding constants and extended the Blueprint and Grammar interfaces with new methods; added corresponding mock methods for boolean and custom column definitions.
HTTP, Validation & Support Updates
(e.g. http/context.go,
http/service_provider.go,
validation/options.go,
validation/service_provider.go,
validation/validation.go,
validation/validation_test.go,
support/collect/collect.go,
support/constant.go,
support/database/database.go,
support/database/database_test.go)
Updated validation functions to include a context parameter and revised test cases accordingly; migrated helper functions (Reverse and Shuffle) to use the mutable package; simplified pointer handling in support/database; and bumped the version constant.
go.mod Upgraded the Go version and updated multiple dependency versions for improved compatibility.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant SP as ServiceProvider
    participant Cont as Container
    participant Con as Contracts
    App->>SP: Call Register(app)
    SP->>Cont: app.Singleton(Con.BindingX, func(app){...})
    Cont-->>SP: Service bound
    SP-->>App: Registration complete
Loading
sequenceDiagram
    participant Dev as Developer
    participant CA as ConsoleApplication
    Dev->>CA: NewApplication(name, usage, usageText, version, useArtisan)
    CA->>CA: Initialize instance with useArtisan flag
    CA-->>Dev: Return configured application instance
Loading

Possibly related PRs

  • fix: Problem with submodels id string  #903: Modifies the auth test methods to ensure consistent timestamp usage by replacing multiple calls to carbon.Now() with a single variable.
  • chore: merge v1.15.3 #842: Also addresses changes in the auth tests, specifically improving how timestamps are set in TestParse_Success and TestParse_SuccessWithPrefix.

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

@hwbrzzl hwbrzzl changed the base branch from master to v1.15.x February 27, 2025 09:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR fixes an issue where the context in PrepareForValidation was always nil and makes several related improvements. Key changes include:

  • Updating service providers to use binding constants from the contracts package.
  • Adding support for a boolean column type in MySQL and PostgreSQL grammars, with accompanying tests.
  • Refactoring the console application to use a unified "useArtisan" flag.

Reviewed Changes

File Description
contracts/binding.go Adds binding constants for various components.
config/service_provider.go Updates singleton binding to use contracts.BindingConfig.
database/schema/grammars/*.go Introduces a new TypeBoolean method for MySQL and PostgreSQL.
database/schema/blueprint*.go Adds Boolean and Column methods to the blueprint, along with test coverage.
database/orm/orm.go Refactors refresh call to use contracts.BindingOrm.
console/, crypt/, auth/, cache/ Updates service providers to use binding constants and adjusts application signatures.
console/application.go Replaces isArtisan with useArtisan and updates tests accordingly.

Copilot reviewed 59 out of 59 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

database/gorm/logger.go:14

  • The removal of the env.IsArtisan() check may affect the log level configuration in certain contexts. Please confirm that this change is intentional and that it does not lead to unintended behavior in environments that previously relied on this condition.
-	if env.IsArtisan() {

console/application_test.go:16

  • Currently, tests only verify behavior for useArtisan=true. Consider adding test cases for useArtisan=false to ensure the application behaves as expected in non-artisan mode.
cliApp := NewApplication("test", "test", "test", "test", true)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: b8bf942 Previous: e26aa18 Ratio
Benchmark_EncryptString 6521 ns/op 2160 B/op 15 allocs/op 2209 ns/op 2160 B/op 15 allocs/op 2.95
Benchmark_EncryptString - ns/op 6521 ns/op 2209 ns/op 2.95
Benchmark_DecryptString 6770 ns/op 2040 B/op 17 allocs/op 2042 ns/op 2040 B/op 17 allocs/op 3.32
Benchmark_DecryptString - ns/op 6770 ns/op 2042 ns/op 3.32

This comment was automatically generated by workflow using github-action-benchmark.

@codecov
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.

Please upload report for BASE (v1.15.x@05a7f44). Learn more about missing BASE report.

Files with missing lines Patch % Lines
validation/validation.go 66.66% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             v1.15.x     #917   +/-   ##
==========================================
  Coverage           ?   68.61%           
==========================================
  Files              ?      218           
  Lines              ?    18891           
  Branches           ?        0           
==========================================
  Hits               ?    12963           
  Misses             ?     5258           
  Partials           ?      670           

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

@hwbrzzl hwbrzzl merged commit ebdee39 into v1.15.x Feb 28, 2025
11 of 12 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#589 branch February 28, 2025 02:48
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.

Context in PrepareForValidation always nil

2 participants