Skip to content

Fix handling of null columns in PostgresProcessor processIndexes. #53936

@securit

Description

@securit

Laravel Version

11.35.1

PHP Version

8.3.14

Database Driver & Version

8.3.14

Description

Previously, null values in the columns field caused issues during the explode operation. This fix ensures that explode is only called when columns is not null, preventing potential errors, depreaction warnings and improving data consistency.

Background:

When indexes are created with an expression, Indexes on Expressions rather than a table column, php raises a deprecation warning message LOG.warning: explode(): Passing null to parameter #2 ($string) of type string is deprecated in vendor/laravel/framework/src/Illuminate/Database/Query/Processors/PostgresProcessor.php on line 127

This is particularly evident when using indexes based on expressions rather than indexes based on a table column. An example of why you would want to do this might be indexing based upon an aggregation of the year in a timestamp field.

$table->rawIndex("DATE_TRUNC('year'::text,created_at)", 'radar_records_created_at_trunc_year_idx');

Steps To Reproduce

Create a table in a migration with a functional index

Schema::table('test_records', static function (Blueprint $table) {
            $table->index('id');
            $table->timestamps();
            $table->rawIndex("DATE_TRUNC('year'::text,created_at)", 'test_records_created_at_trunc_year_idx');

Create a call to get indexes

$schema=DB::connection()->getSchemaBuilder();
$indexes = $schema->getIndexes('test_records');

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions