tpetry / laravel-postgresql-enhanced

Support for many missing PostgreSQL specific features
MIT License
772 stars 31 forks source link

Index compilation broken with Laravel 10 #53

Closed hendrikheil closed 1 year ago

hendrikheil commented 1 year ago

We just upgraded to Laravel 10, but encountered an issue with our index compilation. We're actually using CockroachDB, not PostgreSQL but the use-case should be identical and behave the same for both. In our migrations we have some columns as jsonb and we're adding a GIN index on an attribute of that JSON column.

The migration looks like this:

Schema::create('examples', function (Blueprint $table) {
    $table->jsonb('meta');
    $table->rawIndex('("meta"->\'attribute\')', 'examples_meta_attribute_index')->algorithm('gin');
});

However starting with Laravel 10, expressions can't just be cast to string. This means that this line is now not applicable for all possible cases: https://github.com/tpetry/laravel-postgresql-enhanced/blob/aea2a6a6c727a2ffeb92c5473bcee8ad88c115ff/src/Schema/Grammars/GrammarIndex.php#L132

I believe fixing it would be as simple as changing from string to string|Expression and adding the same functionality that already exists in laravel-query-expressions as stringize https://github.com/tpetry/laravel-query-expressions/blob/4ca06ed9abf0ac5e52f83a613124389d4c03392b/src/Concerns/StringizeExpression.php#L12-L18

There are possibly more cases where there is currently an expectation for string but we might receive an Expression instead.

I'm happy to send a pull-request, but I'm not quite sure how one gets those fancy numbers for columns and tables that are used in other tests :)

tpetry commented 1 year ago

Will be fixed in about an hour ;)

hendrikheil commented 1 year ago

Is there documentation for writing tests for this library somewhere? I'd love to be able to contribute with the projects best practices!

tpetry commented 1 year ago

Its fixed with release 0.27.1. The problem was not changed in Laravel 10. I never handled rawIndex definitions correctly. They are not mentioned in the documentation so I completely missed them.

There's no real documentation for tests, its just PHPUnit with some additions. The numbers at the end of everything are just random nums to prevent name clashes.

As I rewrite every PR the best approach would be just asking whether I am ok with a certain feature, work on a draft and I polish it up to fit my style. Or the way I would do it.