Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended PostgreSQL types are not supported with the Laravel IDE Helper Generator #40

Closed
patrickcurl opened this issue Sep 15, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@patrickcurl
Copy link

When running composer update which regenerates ide-helper stubs, I go this as it was analyzing the models.

Exception: Unknown database type citext requested, Doctrine\DBAL\Platforms\PostgreSQL100Platform may not support it.
Could not analyze class App\Models\Tag.

The fix was easy enough, in AppServiceProvider I put:

<?php
// ...
use Tpetry\PostgresqlEnhanced\Types\CitextType;
class AppServiceProvider extends ServiceProvider
{
...
    public function boot(){
        \app('db')->registerDoctrineType(CitextType::class, 'citext', 'string');
        // ...
    }

As I was looking at the code in the vendor folder, I noticed the $typeInstance->getName() is deprecated in doctrine, not sure if that is related,and I'm not sure that's the best way to register the doctrine type, but it made the error go away..

@tpetry
Copy link
Owner

tpetry commented Sep 15, 2022

Hi Patrick, this is not a problem of this driver. Doctrine can not handle many of the PostgreSQL types and will throw that exact exception, it's doing that within Laravel migrations too. I "patched" Laravel migrations by adding many of the missing PostgreSQL types to Doctrine. But the types are currently only added when migrations are executed.

Does it solve the problem when the registerDoctrineTypes call is moved to the register method and not only called when the migrator is started? Does the stubs generator broadcast a custom event so I could listen for the event to not register the types for every Laravel boot?
https://github.com/tpetry/laravel-postgresql-enhanced/blob/master/src/PostgresqlEnhancedServiceProvider.php#L94

@tpetry tpetry changed the title Bug: Exception: Unknown database type citext requested, Doctrine\DBAL\Platforms\PostgreSQL100Platform may not support it. Extended PostgreSQL types are not supported with the Laravel IDE Helper Generator Sep 15, 2022
@patrickcurl
Copy link
Author

patrickcurl commented Sep 21, 2022

@tpetry
I just installed the spatie/laravel-model-info package, and noticed that somewhere up the chain the citext type didn't persist.

However, when I changed:

\app('db')->registerDoctrineType(\Tpetry\PostgresqlEnhanced\Types\CitextType::class, 'citext', 'string');

to:

$this->app['db']->connection()->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('citext', 'string');

Everything worked.

I also submitted a PR on that package to just add 'citext' => 'string' to their typeMapping array. see: spatie/laravel-model-info#15

Edit: Fun fact, github copilot basically solved this by suggesting the second snippet up there, after I put in $this->app['db'] as I was just using ide tools to guess the api chain to insert everything at the right spot.

Edit #2
This was added to boot() method in AppServiceProvider.php.

Haven't tried it in register().

@robsontenorio
Copy link
Contributor

Just place this on ide-helper.php config file

image

@tpetry tpetry added the bug Something isn't working label Dec 16, 2022
@tpetry
Copy link
Owner

tpetry commented Jan 13, 2023

@patrickcurl Can you try again with 0.25.1? All artisan commands now have access to the advanced data types.

@patrickcurl
Copy link
Author

@tpetry i think it's resolved, otherwise I jerry rigged it to work, so I think this can be closed. Thanks!

@tpetry
Copy link
Owner

tpetry commented Jan 28, 2023

Awesome! One problem less when using PG.

@tpetry tpetry closed this as completed Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants