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

feat: consolidate schema options formatting #241

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

taka-oyama
Copy link
Collaborator

@taka-oyama taka-oyama commented Nov 8, 2024

Summary by CodeRabbit

  • New Features

    • Introduced support for invisible columns, change streams using Blueprint, and snapshot queries.
    • Added new methods for formatting options and handling sequences and change streams.
  • Bug Fixes

    • Addressed issues with schema changes being applied multiple times.
  • Documentation

    • Updated CHANGELOG.md to reflect the latest version and changes.

@taka-oyama taka-oyama added enhancement New feature or request waiting for review labels Nov 8, 2024
@taka-oyama taka-oyama requested a review from a team November 8, 2024 04:29
@taka-oyama taka-oyama self-assigned this Nov 8, 2024
@colopl colopl deleted a comment from coderabbitai bot Nov 8, 2024
@taka-oyama taka-oyama mentioned this pull request Nov 8, 2024
15 tasks
Copy link

coderabbitai bot commented Nov 8, 2024

Walkthrough

The pull request includes updates to the CHANGELOG.md to document the release of version 8.3.0, which introduces new features such as support for invisible columns, change streams, and snapshot queries. The Connection::getDatabaseContext() method has been deprecated, while new methods like UseMutations::getMutationExecutor() and Query\Builder::whereNotInUnnest(...) have been added. Additionally, existing methods have been modified for improved functionality. Changes also encompass the SharedGrammarCalls trait and the Grammar class, enhancing option formatting and method signatures.

Changes

File Change Summary
CHANGELOG.md Updated for version 8.3.0 release; added new features, deprecated methods, and modifications to existing methods.
src/Connection.php Deprecated Connection::getDatabaseContext(), updated Connection::setCommitOptions(...).
src/UseMutations.php Added UseMutations::getMutationExecutor().
src/Query/Builder.php Added Query\Builder::whereNotInUnnest(...), modified Query\Builder::whereIn(...) to wrap values in UNNEST for over 950 values.
src/Concerns/SharedGrammarCalls.php Added protected function formatOptions(array $options, string $delimiter = '='): string, added protected function formatOptionValue(mixed $value): string.
src/Schema/Grammar.php Updated formatSequenceOptions and formatChangeStreamOptions to use formatOptions, updated method signatures for compileDropSequence and compileDropSequenceIfExists to accept object type for $command.

Possibly related PRs

  • feat: add change stream support #230: This PR adds support for change streams, which is a key feature mentioned in the main PR's summary, indicating a direct relationship in functionality.
  • feat: invisble columns support #240: This PR introduces support for invisible columns, which is also highlighted in the main PR's summary as part of the new features in version 8.3.0.

Suggested reviewers

  • halnique
  • Uyan712

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

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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
src/Concerns/SharedGrammarCalls.php (2)

48-59: Add documentation examples and handle empty array case.

The method looks good but could benefit from these improvements:

  1. Add usage examples in the docblock
  2. Consider handling empty array case explicitly
     /**
      * @param array<string, scalar|BackedEnum> $options
      * @param string $delimiter
      * @return string
+     * @example
+     * formatOptions(['max_length' => 100, 'nullable' => true]) // 'max_length=100, nullable=true'
+     * formatOptions(['enum_value' => Status::ACTIVE]) // 'enum_value=ACTIVE'
      */
     protected function formatOptions(array $options, string $delimiter = '='): string
     {
+        if (empty($options)) {
+            return '';
+        }
         $mapped = Arr::map($options, function (int|float|bool|string|BackedEnum $v, string $k) use ($delimiter): string {
             return Str::snake($k) . $delimiter . $this->formatOptionValue($v);
         });
         return implode(', ', $mapped);
     }

61-73: Enhance type safety and validation.

While the implementation is clean, consider these improvements for better type safety:

  1. The mixed type hint with @param scalar|BackedEnum could be misleading
  2. Add validation for unexpected types
     /**
      * @param scalar|BackedEnum $value
      * @return string
+     * @throws \InvalidArgumentException If value is not scalar or BackedEnum
      */
-    protected function formatOptionValue(mixed $value): string
+    protected function formatOptionValue(int|float|string|bool|BackedEnum $value): string
     {
         return match (true) {
             is_bool($value) => $value ? 'true' : 'false',
             is_string($value) => $this->quoteString($value),
             $value instanceof BackedEnum => $this->formatOptionValue($value->value),
-            default => (string) $value,
+            is_scalar($value) => (string) $value,
+            default => throw new \InvalidArgumentException('Unexpected value type'),
         };
     }
CHANGELOG.md (1)

Line range hint 1-10: Consider categorizing changes for better readability.

While the changes are well-documented, consider organizing them into categories like "Added", "Changed", and "Deprecated" for better clarity. This would align with the format used in previous versions and make it easier for users to understand the impact of changes.

Example structure:

# v8.3.0 (2024-11-08)

+Added:
- add support for invisible columns (#240)
- add support for change streams using Blueprint (#230)
- add support for snapshot queries (#215)
- add support for `Query\Builder::whereNotInUnnest(...)` (#225)

+Changed:
- consolidate schema options formatting (#241)
- `Query\Builder::whereIn` will now wrap values in `UNNEST` if the number of values exceeds the limit (950). (#226)
- Commit options can now be set through config or through `Connection::setCommitOptions(...)` (#229)

+Deprecated:
- deprecate Connection::getDatabaseContext() and move logic to UseMutations::getMutationExecutor() (#227)
src/Schema/Grammar.php (1)

330-332: Consider simplifying the empty check.

The current implementation could be more concise.

-        return $options !== []
-            ? 'options (' . $this->formatOptions($options) . ')'
-            : '';
+        return $options === [] ? '' : 'options (' . $this->formatOptions($options) . ')';
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e60ce6b and bff2c79.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • src/Concerns/SharedGrammarCalls.php (2 hunks)
  • src/Schema/Grammar.php (2 hunks)
🔇 Additional comments (5)
src/Concerns/SharedGrammarCalls.php (2)

20-23: LGTM! Required imports for the new functionality.


48-73: Verify the usage of new formatting methods.

Let's confirm that these new methods are being used consistently across the codebase.

✅ Verification successful

Let me try a different approach to verify the usage of these methods.


Methods are used correctly in the Schema Grammar implementation

The verification shows that these formatting methods are properly used within the codebase:

  • formatOptions() is called in src/Schema/Grammar.php for handling schema options
  • formatOptionValue() is used internally within SharedGrammarCalls trait for value formatting
  • The implementation follows a consistent pattern for options formatting across the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check usage of formatOptions and formatOptionValue methods
# Expected: Find calls in formatSequenceOptions and formatChangeStreamOptions

echo "Checking for method usage..."
ast-grep --pattern 'function formatSequenceOptions($$$) {
  $$$
  formatOptions($$$)
  $$$
}'

ast-grep --pattern 'function formatChangeStreamOptions($$$) {
  $$$
  formatOptions($$$)
  $$$
}'

Length of output: 262


Script:

#!/bin/bash
# Search for any calls to formatOptions and formatOptionValue
echo "Searching for formatOptions calls..."
rg "formatOptions\(" -A 2

echo -e "\nSearching for formatOptionValue calls..."
rg "formatOptionValue\(" -A 2

echo -e "\nSearching for class implementations..."
ast-grep --pattern 'trait SharedGrammarCalls {
  $$$
}'

Length of output: 1731

CHANGELOG.md (1)

Line range hint 12-1000: LGTM! The changelog maintains good documentation practices.

The changelog demonstrates consistent formatting, clear marking of breaking changes, and proper referencing of PRs. The inclusion of important notes about version requirements and the clear categorization of changes in previous versions makes it easy for users to understand the evolution of the codebase.

src/Schema/Grammar.php (2)

265-265: LGTM! Method signature improvements enhance type safety.

The changes to method signatures improve type safety by:

  1. Adding explicit return types
  2. Making the parameter type more flexible by using object instead of Fluent

Also applies to: 330-332


265-265: LGTM! Improved code maintainability through consolidation.

The refactoring to use formatOptions from the SharedGrammarCalls trait reduces code duplication and improves consistency in option formatting.

@taka-oyama taka-oyama merged commit f3d950b into master Nov 8, 2024
1 check passed
@taka-oyama taka-oyama deleted the feature/consolidate-options branch November 8, 2024 05:53
@coderabbitai coderabbitai bot mentioned this pull request Dec 24, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants