Skip to content

Conversation

alecritson
Copy link
Collaborator

@alecritson alecritson commented Aug 18, 2025

#2278 Removed the jsonb changes from shipping tables but didn't reapply them via the shipping addon. This PR mimics the core migration but within the shipping addon.

Summary by CodeRabbit

  • Chores
    • Migrated shipping method data storage to a more efficient format on PostgreSQL, improving query performance and scalability.
    • Backward-compatible and reversible; no action required for non-PostgreSQL setups.
    • Ensures more consistent behavior and prepares the system for future enhancements.
    • Seamless upgrade path with automatic migration during update; no user-facing changes expected.

@alecritson alecritson requested a review from glennjacobs August 18, 2025 07:34
Copy link

vercel bot commented Aug 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
lunar-docs Ready Ready Preview Comment Aug 18, 2025 7:34am

Copy link
Contributor

coderabbitai bot commented Aug 18, 2025

Walkthrough

Adds a PostgreSQL-specific migration that alters shipping_methods.data from JSON to JSONB in up(), with a reversible down() to switch back to JSON. The migration no-ops for non-PostgreSQL drivers and respects the table prefix.

Changes

Cohort / File(s) Summary
Database migration
packages/table-rate-shipping/database/migrations/2025_08_18_100000_switch_shipping_to_jsonb_columns.php
New migration class SwitchShippingToJsonbColumns; up() alters shipping_methods.data to jsonb; down() reverts to json; guarded to run only on PostgreSQL and uses table prefix.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • glennjacobs

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ensure-jsonb-columns-for-shipping

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
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: 2

🧹 Nitpick comments (3)
packages/table-rate-shipping/database/migrations/2025_08_18_100000_switch_shipping_to_jsonb_columns.php (3)

17-19: Bind Schema operations to the configured Lunar connection.

Since Migration::getConnection() overrides the connection, explicitly binding Schema to that connection avoids any ambiguity if the default app connection differs.

Apply this diff:

-        Schema::table($this->prefix.'shipping_methods', function (Blueprint $table) {
+        Schema::connection($this->getConnection())->table($this->prefix.'shipping_methods', function (Blueprint $table) {
             $table->jsonb('data')->nullable()->change();
         });

29-31: Do the same in down() for consistency.

Apply this diff:

-        Schema::table($this->prefix.'shipping_methods', function (Blueprint $table) {
+        Schema::connection($this->getConnection())->table($this->prefix.'shipping_methods', function (Blueprint $table) {
             $table->json('data')->nullable()->change();
         });

17-19: Optional hardening: guard when table/column is missing.

If the addon is installed in an environment where the table doesn’t exist yet (or during partial setup), guarding avoids migration failures.

Minimal guard (assuming you adopt connection binding suggested earlier):

-        Schema::connection($this->getConnection())->table($this->prefix.'shipping_methods', function (Blueprint $table) {
+        $schema = Schema::connection($this->getConnection());
+        if (! $schema->hasTable($this->prefix.'shipping_methods') || ! $schema->hasColumn($this->prefix.'shipping_methods', 'data')) {
+            return;
+        }
+        $schema->table($this->prefix.'shipping_methods', function (Blueprint $table) {
             $table->jsonb('data')->nullable()->change();
         });
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ecb4b46 and 58e14ce.

📒 Files selected for processing (1)
  • packages/table-rate-shipping/database/migrations/2025_08_18_100000_switch_shipping_to_jsonb_columns.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/table-rate-shipping/database/migrations/2025_08_18_100000_switch_shipping_to_jsonb_columns.php (2)
packages/core/src/Facades/DB.php (1)
  • DB (116-128)
packages/core/src/Base/Migration.php (1)
  • Migration (7-38)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: search - PHP 8.4 - L12.* ↑
  • GitHub Check: core - PHP 8.4 - L12.* ↑
  • GitHub Check: stripe - PHP 8.4 - L12.* ↑
  • GitHub Check: shipping - PHP 8.4 - L12.* ↑ E
  • GitHub Check: shipping - PHP 8.4 - L12.* ↑
  • GitHub Check: search - PHP 8.4 - L11.* ↑ E
  • GitHub Check: admin - PHP 8.4 - L12.* ↑
  • GitHub Check: admin - PHP 8.4 - L12.* ↑ E
  • GitHub Check: core - PHP 8.4 - L12.* ↑ E
  • GitHub Check: core - PHP 8.4 - L11.* ↑ E
  • GitHub Check: admin - PHP 8.4 - L11.* ↑
  • GitHub Check: core - PHP 8.4 - L11.* ↑
  • GitHub Check: admin - PHP 8.3 - L12.* ↑
  • GitHub Check: core - PHP 8.3 - L12.* ↑ E
  • GitHub Check: core - PHP 8.3 - L12.* ↑
  • GitHub Check: admin - PHP 8.3 - L12.* ↑ E
  • GitHub Check: admin - PHP 8.3 - L11.* ↑
  • GitHub Check: core - PHP 8.3 - L11.* ↑ E
  • GitHub Check: admin - PHP 8.3 - L11.* ↑ E
  • GitHub Check: core - PHP 8.3 - L11.* ↑
🔇 Additional comments (3)
packages/table-rate-shipping/database/migrations/2025_08_18_100000_switch_shipping_to_jsonb_columns.php (3)

10-20: Dependency check passed: doctrine/dbal is already required
The composer.json shows doctrine/dbal (version ^3.6) in the main require section, so the ->change() call on the jsonb column will work as intended. No further action needed.


18-18: shipping_methods.data column remains nullable

The original migration (2022_04_28_110000_create_shipping_methods_table.php:19) defines the data column as

$table->json('data')->nullable();

The new migration switches its type to jsonb and still applies ->nullable(), so nullability is unchanged. No schema adjustment is needed here.


17-19: Verification Complete: Only one JSON column present
I searched the table-rate-shipping migrations and package code and found no other ->json/->jsonb columns—shipping_methods.data is the sole JSON field. This migration covers all JSON columns in the addon, so no further changes are required.

@glennjacobs
Copy link
Contributor

@alecritson thanks! Saved me a job.

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.

2 participants