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

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

Closed
isaackearl opened this issue Jul 2, 2017 · 2 comments
Assignees

Comments

@isaackearl
Copy link

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.

@guiwoda
Copy link

guiwoda commented Jul 3, 2017

@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 ?

@isaackearl
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants