When using nocache database driver and accessing urls that are longer than the max length of the column it throws a 500 error for that page. This happend to advertisement links, where Meta/Google adds a lot of parameters to the url, causing it to exceed the varchar limit.
Only changing the column type to text was not possible due to the existing index on url. We have fixed this issue temporarily by creating a migration like this:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
// Drop index first
Schema::table('nocache_regions', function (Blueprint $table) {
$table->dropIndex('nocache_regions_url_index');
});
// Change column type
Schema::table('nocache_regions', function (Blueprint $table) {
$table->text('url')->change();
});
// Add index with length using raw SQL
DB::statement('ALTER TABLE nocache_regions ADD INDEX nocache_regions_url_index (url(255))');
}
public function down()
{
// Remove index
DB::statement('ALTER TABLE nocache_regions DROP INDEX nocache_regions_url_index');
// Change column back to varchar
Schema::table('nocache_regions', function (Blueprint $table) {
$table->string('url', 255)->change();
});
// Recreate original index
Schema::table('nocache_regions', function (Blueprint $table) {
$table->index('url', 'nocache_regions_url_index');
});
}
};
How to reproduce
Set up half static caching
Use nocache tags on a page
Make use of nocache database driver
Visit a page with long url (for example with a lot of parameters)
See error 500 showing up as below:
Logs
SQLSTATE: String data, right truncated: 1406 Data too long for column 'url' at row 1 (Connection: mysql, SQL: insert into `nocache_regions` (`key`, `url`, `region`, `updated_at`, `created_at`)
Bug description
When using nocache database driver and accessing urls that are longer than the max length of the column it throws a 500 error for that page. This happend to advertisement links, where Meta/Google adds a lot of parameters to the url, causing it to exceed the
varchar
limit.Only changing the column type to
text
was not possible due to the existing index onurl
. We have fixed this issue temporarily by creating a migration like this:How to reproduce
Logs
Environment
Installation
Starter Kit using via CLI
Additional details
No response