Skip to content

Increase delivery_instructions column length in address-related tables#2247

Merged
glennjacobs merged 3 commits intolunarphp:1.xfrom
Huncsuga:fix/increase_delivery_instructions_field_length
Aug 14, 2025
Merged

Increase delivery_instructions column length in address-related tables#2247
glennjacobs merged 3 commits intolunarphp:1.xfrom
Huncsuga:fix/increase_delivery_instructions_field_length

Conversation

@Huncsuga
Copy link
Contributor

@Huncsuga Huncsuga commented Jul 18, 2025

This pull request updates the delivery_instructions column in the lunar_addresses, lunar_cart_addresses, and lunar_order_addresses tables from VARCHAR(255) to TEXT.

This change ensures that users can provide longer delivery instructions without encountering SQL errors such as:

SQLSTATE[22001]: Data too long for column 'delivery_instructions'

Fixes #2245

Summary by CodeRabbit

  • New Features
    • Increased the maximum length of delivery instructions to 1000 characters for addresses, cart addresses, and order addresses.

@vercel
Copy link

vercel bot commented Jul 18, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 5, 2025 8:40am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 18, 2025

Walkthrough

A new migration updates the delivery_instructions column in the addresses, cart_addresses, and order_addresses tables. The migration increases the column length to 1000 characters while keeping it nullable, and provides a rollback to the default length. No other code or schema changes are present.

Changes

Cohort / File(s) Change Summary
Migration: Update delivery_instructions columns
packages/core/database/migrations/2025_08_05_083800_update_delivery_instructions_columns.php
Adds a migration to alter the delivery_instructions column to a string(1000), nullable, in addresses, cart_addresses, and order_addresses tables; includes rollback to default length.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5-10 minutes

Assessment against linked issues

Objective Addressed Explanation
Increase delivery_instructions field length to allow longer messages in address-related tables (#2245)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f8bfa8f and be1514e.

📒 Files selected for processing (1)
  • packages/core/database/migrations/2025_08_05_083800_update_delivery_instructions_columns.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/database/migrations/2025_08_05_083800_update_delivery_instructions_columns.php (1)
packages/core/src/Base/Migration.php (1)
  • Migration (7-38)
🔇 Additional comments (3)
packages/core/database/migrations/2025_08_05_083800_update_delivery_instructions_columns.php (3)

1-8: LGTM! Proper migration structure.

The file follows Laravel migration conventions correctly, with appropriate imports and extends the Lunar base migration class to utilize table prefixing.


12-25: Excellent implementation that addresses the core issue.

The migration correctly increases the delivery_instructions column length from 255 to 1000 characters across all three address-related tables. This change:

  • Resolves the SQL error SQLSTATE[22001]: Data too long for column mentioned in issue Increase delivery_instructions Field Length Across Address Tables #2245
  • Aligns with the PR discussion consensus to use VARCHAR(1000) instead of TEXT for performance considerations
  • Maintains consistency across addresses, cart_addresses, and order_addresses tables
  • Preserves the nullable constraint appropriately

30-43: Rollback implementation is correct but consider data truncation risk.

The rollback functionality properly reverts the column changes. However, be aware that rolling back this migration could truncate any existing delivery instructions longer than 255 characters, potentially causing data loss.

This is expected behavior for column size reductions, but consider documenting this risk or implementing data validation before rollback in production environments.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @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 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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests 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.

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)
packages/core/database/migrations/2025_07_18_081937_update_delivery_instructions_columns.php (2)

14-24: Condense repetitive Schema::table() calls & honour custom connection

The three almost-identical blocks are classic duplication.
Wrapping the table names in an array and iterating keeps the intent crystal-clear, prevents copy-paste drift, and makes future changes (e.g. adding another address table) one-liner simple.
While touching this, call Schema::connection($this->getConnection()) so the migration respects lunar.database.connection.

-        Schema::table($this->prefix.'addresses', function (Blueprint $table) {
-            $table->text('delivery_instructions')->nullable()->change();
-        });
-
-        Schema::table($this->prefix.'cart_addresses', function (Blueprint $table) {
-            $table->text('delivery_instructions')->nullable()->change();
-        });
-
-        Schema::table($this->prefix.'order_addresses', function (Blueprint $table) {
-            $table->text('delivery_instructions')->nullable()->change();
-        });
+        foreach (['addresses', 'cart_addresses', 'order_addresses'] as $tbl) {
+            Schema::connection($this->getConnection())
+                ->table($this->prefix.$tbl, function (Blueprint $table) {
+                    $table->text('delivery_instructions')->nullable()->change();
+                });
+        }

32-42: Apply the same DRY principle in down()

Mirror the loop used in up() so the rollback path stays in sync and equally maintainable.

-        Schema::table($this->prefix.'addresses', function (Blueprint $table) {
-            $table->string('delivery_instructions', 255)->nullable()->change();
-        });
-
-        Schema::table($this->prefix.'cart_addresses', function (Blueprint $table) {
-            $table->string('delivery_instructions', 255)->nullable()->change();
-        });
-
-        Schema::table($this->prefix.'order_addresses', function (Blueprint $table) {
-            $table->string('delivery_instructions', 255)->nullable()->change();
-        });
+        foreach (['addresses', 'cart_addresses', 'order_addresses'] as $tbl) {
+            Schema::connection($this->getConnection())
+                ->table($this->prefix.$tbl, function (Blueprint $table) {
+                    $table->string('delivery_instructions', 255)->nullable()->change();
+                });
+        }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cec97ad and f8bfa8f.

📒 Files selected for processing (1)
  • packages/core/database/migrations/2025_07_18_081937_update_delivery_instructions_columns.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/database/migrations/2025_07_18_081937_update_delivery_instructions_columns.php (1)
packages/core/src/Base/Migration.php (1)
  • Migration (7-38)
🔇 Additional comments (1)
packages/core/database/migrations/2025_07_18_081937_update_delivery_instructions_columns.php (1)

30-42: Rollback may silently truncate data longer than 255 chars

If anyone has already stored >255-char instructions, down() will coerce them into VARCHAR(255) without warning, leading to silent data loss or migration failure (depending on SQL mode).

Mitigate by:
• Logging a warning or throwing if rows exist with overlength data before altering,
• or documenting the risk in the migration description / release notes.

@wychoong
Copy link
Contributor

SQLSTATE[22001]: Data too long for column 'delivery_instructions'

There is no need to increase from VARCHAR(255) to TEXT, could be just 500
Or better, your input field should limit input to 255

@Huncsuga
Copy link
Contributor Author

Huncsuga commented Jul 21, 2025

@wychoong Why do you think TEXT wouldn't be need here? Do you see any drawback to using it, or do you think 500 characters would be enough for all future cases?

@wychoong
Copy link
Contributor

Do you see any drawback to using it,

yes. depends on database engine (read/write performance, storage)

or do you think 500 characters would be enough for all future cases?

will it be enough for all future cases? maybe, maybe not. but it needs to be reasonable.
TEXT support 65,535 characters. is it reasonable for delivery instructions? I don't think so.

refer to your issue

Attempt to submit an address form (e.g. as a guest) with a longer delivery_instructions message (e.g. over 255 characters).

it's apparent there is no validation and limit on user input. are we going to increase from TEXT 65,535 characters to LONGTEXT? (well, this is exaggerating)

@KingaOrsii
Copy link
Contributor

KingaOrsii commented Jul 21, 2025

We actually had a user (in production) who entered a longer instruction (over 255 characters) and encountered a server error due to the column size constraint. That’s what prompted us to consider increasing the limit.

If we do decide to go beyond 255, I believe it makes more sense to raise it to at least 1,000 or even 2,000 characters. Increasing it only slightly (e.g., to 500) doesn’t provide much practical benefit, as longer inputs would still be cut off and result in a poor user experience.

So if you suggest enforcing a limit, @wychoong, I’d propose setting it to 2,000 characters.

BUT

Storage-wise, there’s not much difference between VARCHAR(2000) and TEXT for this use case. Both handle ~2000 chars efficiently, and the impact on performance or disk space is minimal. The choice mainly depends on whether we want a fixed length (VARCHAR) or more flexibility (TEXT), and so I think the second option is better.

@glennjacobs
Copy link
Contributor

I would suggest we use VARCHAR(1000). There's no real reason for this to be a TEXT field. Varchar will be more optimised for this usage.

Re: the server error - was this on the frontend or the admin panel?

@Huncsuga
Copy link
Contributor Author

Huncsuga commented Aug 5, 2025

Alright, I’ll update it as suggested.
The server error happened on the frontend.

@Huncsuga
Copy link
Contributor Author

Huncsuga commented Aug 5, 2025

@glennjacobs I’ve made the requested changes.

@glennjacobs glennjacobs merged commit 97591e1 into lunarphp:1.x Aug 14, 2025
47 checks passed
@Huncsuga Huncsuga deleted the fix/increase_delivery_instructions_field_length branch December 14, 2025 15:15
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.

Increase delivery_instructions Field Length Across Address Tables

5 participants