Ensure shipping table json fields are set to jsonb#2279
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
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 unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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.
📒 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
Thecomposer.jsonshowsdoctrine/dbal(version ^3.6) in the mainrequiresection, so the->change()call on thejsonbcolumn will work as intended. No further action needed.
18-18: shipping_methods.data column remains nullableThe original migration (
2022_04_28_110000_create_shipping_methods_table.php:19) defines thedatacolumn as$table->json('data')->nullable();The new migration switches its type to
jsonband 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/->jsonbcolumns—shipping_methods.datais the sole JSON field. This migration covers all JSON columns in the addon, so no further changes are required.
...ble-rate-shipping/database/migrations/2025_08_18_100000_switch_shipping_to_jsonb_columns.php
Show resolved
Hide resolved
...ble-rate-shipping/database/migrations/2025_08_18_100000_switch_shipping_to_jsonb_columns.php
Show resolved
Hide resolved
|
@alecritson thanks! Saved me a job. |
There was a problem hiding this comment.
Pull Request Overview
Adds a migration to switch the shipping_methods.data column to jsonb on PostgreSQL (and revert to json on rollback), aligning the shipping addon with core migrations for performance and consistency.
- Adds up/down migration guarded to only run on PostgreSQL.
- Alters shipping_methods.data column type between json and jsonb.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...ble-rate-shipping/database/migrations/2025_08_18_100000_switch_shipping_to_jsonb_columns.php
Outdated
Show resolved
Hide resolved
…m/lunarphp/lunar into ensure-jsonb-columns-for-shipping
#2278 Removed the
jsonbchanges 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