phoenix icon indicating copy to clipboard operation
phoenix copied to clipboard

Doctrine2 create database throws exception even if --if-not-exists option is passed

Open ghost opened this issue 11 years ago • 10 comments

Command

$  php app/console --env=test doctrine:database:create --if-not-exists

Exception:

Could not create database for connection named `testSymfony`
An exception occurred while executing 'CREATE DATABASE `testSymfony`':

SQLSTATE[HY000]: General error: 1007 Can't create database 'testSymfony'; database exists
$ composer show -i

doctrine/annotations                     v1.2.3             Docblock Annotations Parser
doctrine/cache                           v1.4.0             Caching library offering an object-oriented API for many cache backends
doctrine/collections                     v1.2               Collections Abstraction library
doctrine/common                          v2.4.2             Common Library for Doctrine projects
doctrine/data-fixtures                   v1.0.0             Data Fixtures for all Doctrine Object Managers
doctrine/dbal                            v2.5.1             Database Abstraction Layer
doctrine/doctrine-bundle                 dev-master 698b10b Symfony DoctrineBundle
doctrine/doctrine-cache-bundle           v1.0.1             Symfony2 Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle        v2.2.0             Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle      dev-master 81575a4 Symfony DoctrineMigrationsBundle
doctrine/inflector                       v1.0.1             Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator                    1.0.4              A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                           v1.0.1             Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                      dev-master 1ac14fa Database Schema migrations using Doctrine DBAL
doctrine/orm                             v2.4.7             Object-Relational-Mapper for PHP

Problem is that database name is quoted because there is no path so this check:

$shouldNotCreateDatabase = $ifNotExists && in_array($name, $tmpConnection->getSchemaManager()->listDatabases());

fails. $ifNotExists is true but testSymfony (with backticks) does not exist in array. testSymfony (without backticks) exists though.

There is also a second bug, sprintf() is missing the database name:

$output->writeln(sprintf('<info>Database for connection named <comment>%s</comment> already exists. Skipped.</info>'));

should be:

$output->writeln(sprintf('<info>Database for connection named <comment>%s</comment> already exists. Skipped.</info>', $name));

ghost avatar Feb 02 '15 11:02 ghost

Same problem in the Drop Command !

asquel avatar Mar 24 '15 16:03 asquel

+1

nnnnathann avatar Apr 06 '15 15:04 nnnnathann

+1

griffithben avatar Apr 06 '15 15:04 griffithben

+1

CharlyP avatar Apr 10 '15 07:04 CharlyP

Related PR: https://github.com/doctrine/DoctrineBundle/pull/385

deeky666 avatar Apr 10 '15 07:04 deeky666

+1

michalkvasnicak avatar Apr 18 '15 10:04 michalkvasnicak

This was fixed in https://github.com/doctrine/DoctrineBundle/pull/401 We really need a new release rolled.

tommygnr avatar Apr 30 '15 16:04 tommygnr

:+1: for a new release :-)

evanpurkhiser avatar May 26 '15 22:05 evanpurkhiser

ping @stof

tommygnr avatar May 27 '15 03:05 tommygnr

For anybody watching this thread a new stable release 1.5 has been tagged with the fix included. Cheers @stof PS: I think this ticket can now be closed

tommygnr avatar May 28 '15 15:05 tommygnr