laravel-doctrine/migrations

Migration in postgres always adds $this->addSql('CREATE SCHEMA public'); to the down() in migration

isaackearl opened this issue · 2 comments

laravel-doctrine/orm 1.3.6 A Doctrine ORM bridge for Laravel 5
laravel-doctrine/scout 0.1.1 A Doctrine bridge for Laravel Scout
laravel/framework v5.4.28 The Laravel Framework.

I run the diff and then the migration and it builds my database etc...
Then I run diff again and it always creates a new migration with this line:

public function down(Schema $schema)
{
    $this->addSql('CREATE SCHEMA public'); 
}

I searched for the issue online and found a similar issue for doctrine on the dbal github: doctrine/dbal#1110

Their is a suggested fix for those using doctrine with symfony...

I was able to implement the fix for myself, but figured I would create this issue in case someone wants to fix it and/or if another searches for a fix. Here is what I did.

I created this file:

<?php

namespace EngineBundle\Doctrine;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;

class MigrationEventSubscriber implements EventSubscriber
{
    public function getSubscribedEvents()
    {
        return array(
            'postGenerateSchema',
        );
    }

    public function postGenerateSchema(GenerateSchemaEventArgs $Args)
    {
        $Schema = $Args->getSchema();

        if (! $Schema->hasNamespace('public')) {
            $Schema->createNamespace('public');
        }
    }
}

Then I put the event subscriber into my doctrine.php config file

'events' => [
    'listeners' => [],
    'subscribers' => [\App\Isaac\Doctrine\Subscribers\MigrationEventSubscriber::class]
],
'filters' => [],

I'm actually not really sure why that fixes it, still learning doctrine and how this config file works... If someone has a better fix let me know.

thanks.

@isaackearl thanks for the heads up!
Personally, I'm not a fan of duplicating doctrine docs in here. What we can do tho is add some sort of warning message on our docs and point to the DBAL issue you linked.

Would you mind opening a PR on https://github.com/laravel-doctrine/docs ?

@guiwoda Ya I went ahead I finally did that. Wasn't sure how much detail to add so I opted for being brief. If you would like me to change the note then let me know. laravel-doctrine/docs#71