-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
DBAL-1168: Schema's getMigrateFromSql always adds CREATE SCHEMA #1110
Comments
Comment created by asentner: I am also having this issue. The down() method always adds: $this->addSql('CREATE SCHEMA public'); Same environment, also using Postgres. Any chance this is on anyone's radar for a release in the near future? |
Comment created by acasademont: Hit by this too. The problem seems to be that the "public" namespace is not added to the table names by default and hence the diff between what postgres says (a "public" schema is created by default in the DB) and what our schema says. I tried to solve this with a workaround by prepending "public." to all table names. It works for the first migration but then in the next migration will try to delete all tables without the "public." and create them again. So that's not working! The solution is assuming that there's always a default 'public' namespace in the Schema.php class. |
Any updates on this? Would be nice to get rid of this in our version files |
As @doctrinebot commented, the problem seems to be here:
the first line builds the schema querying the database
and the second one builds it from the ORM metadata in your application
there is a "public" schema in trying the @doctrinebot workaround
the drop command is without the "public." and I assume that it's to add support to tables without namespaces... I don't see an easy solution for this issue. Either finding a way to define table_1 as an alias for public.table_1 (maybe in postgresql if a database object doesn't have a namespace defined, then the 'public' namespace is attached to it) or removing support in postgresql for no namespace objects, forcing always to define schema="public" for the moment if anybody is working with postgresql and doctrine I suggest to use only the public schema or not use it at all. |
Yep, waiting issue to be resolved |
Can't use |
* Need to revert this after fixes in dbal and orm upstreams
My workaround without modify library and waiting patch. <?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');
}
}
} Register event subscriber. For symfony this can be done in config: # app/config/services.yml
services:
doctrineMigrationDiffListener:
class: EngineBundle\Doctrine\MigrationEventSubscriber
tags:
- { name: doctrine.event_subscriber, connection: default } Works for me, no more useless |
@Melkij What about other schemas? For example when using PostGIS. |
@teohhanhui see my PR #2490 There is |
@teohhanhui I test only public schema. This is just workaround for my project, not complete solution. |
Created a bundle addressing this issue |
If you are using the Laravel doctrine package, here is a workaround: laravel-doctrine/migrations#51 |
If it very old and very hard bug, why not replace constant 'CREATE SCHEMA ' to 'CREATE SCHEMA IF NOT EXISTS ' ? Not beauty, but will no exceptions. |
Silent failures are the worst failures
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
…On Thu, Jul 13, 2017 at 4:17 PM, alemosk ***@***.***> wrote:
If it very old and very hard bug, why not replace constant 'CREATE SCHEMA
' to 'CREATE SCHEMA IF NOT EXISTS ' ?
Not beauty, but will no exceptions.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1110 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAJakEloMbcE7GNgVQTAZ-5UK9C8-EKjks5sNibwgaJpZM4HXQHQ>
.
|
I think, I found a cleaner solution. At least for PostgreSQL. <?php
declare(strict_types=1);
namespace App\EventListener;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use Doctrine\ORM\Tools\ToolEvents;
class FixDefaultSchemaListener implements EventSubscriber
{
/**
* {@inheritdoc}
*/
public function getSubscribedEvents(): array
{
return [
ToolEvents::postGenerateSchema,
];
}
public function postGenerateSchema(GenerateSchemaEventArgs $args): void
{
$schemaManager = $args->getEntityManager()
->getConnection()
->getSchemaManager();
if (!$schemaManager instanceof PostgreSqlSchemaManager) {
return;
}
foreach ($schemaManager->getExistingSchemaSearchPaths() as $namespace) {
if (!$args->getSchema()->hasNamespace($namespace)) {
$args->getSchema()->createNamespace($namespace);
}
}
}
} |
I have also faced with this problem. |
@vudaltsov I don't think this bug happens on anything but Postgres, does it? Maybe create a PR? |
Any updates? |
@antonmedv can you provide a failing test case for the DBAL test suite? |
@igorjacauna I suggest you to switch to hibernate )) |
Is this bug still occurring while using Symfony 4 + Postgres? |
@PedroDiSanti : Yes, this is still occuring |
Thanks, mate. |
This is still occuring. Even when there are no migrations to generate, the following line is added: $this->addSql('CREATE SCHEMA public'); Full generated migration content could be found here. |
Still occurring, got some fresh news? |
@vasilvestre pick up #2490 if you can work on it. |
Anyone know how to implement #1110 (comment) into a symfony4 project? What yaml file does it go into, and where? Any help would be awesome. |
@vudaltsov - legend thanks! |
The command doesn't work and is incorrectly added by DBAL: doctrine/dbal#1110
* Stop trying to create schema in down migrations * Remove `CREATE SCHEMA public` from migrations The command doesn't work and is incorrectly added by DBAL: doctrine/dbal#1110 * Update syntax to match code style * Remove event listener services to separate file * Remove deprecated step from rollback procedure You don't need to remove `CREATE SCHEMA public` commands now because this PR does it for you * Update deleted directory Deleting `var/cache` itself causes a permissions mishap. Instead, delete the contents of that directory like every other script does.
@vudaltsov 2 years later and you're still a legend! |
@vudaltsov Any updates? |
@vudaltsov 3 years later and you're still a legend. |
Notes to self:
Doesn't this mean this is actually a bug in |
Thanks!
|
Hmm actually it is problematic for
And running the |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Jira issue originally created by user vbence:
I originally posted this to Migrations; noticing that all the generated down() methods start with a "CREATE SCHEMA public" line.
Inspecting the return from Schema#getMigrateFromSql it indeed contains the create statement.
The text was updated successfully, but these errors were encountered: