Use actual database name

We can't retrieve the environment within the migration.
And when we ran migration on Travis, database name isn't `database_name` but `test_database_name`.
Retrieve the database name from the connection is more accurate
This commit is contained in:
Jeremy Benoist 2016-12-13 10:31:53 +01:00
parent 3ad4061dba
commit d44016b072
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C

View file

@ -31,7 +31,7 @@ class Version20161022134138 extends AbstractMigration implements ContainerAwareI
{ {
$this->skipIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'This migration only apply to MySQL'); $this->skipIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'This migration only apply to MySQL');
$this->addSql('ALTER DATABASE '.$this->container->getParameter('database_name').' CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;'); $this->addSql('ALTER DATABASE '.$this->connection->getParams()['dbname'].' CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;');
// convert field length for utf8mb4 // convert field length for utf8mb4
// http://stackoverflow.com/a/31474509/569101 // http://stackoverflow.com/a/31474509/569101
@ -62,7 +62,7 @@ class Version20161022134138 extends AbstractMigration implements ContainerAwareI
{ {
$this->skipIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'This migration only apply to MySQL'); $this->skipIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'This migration only apply to MySQL');
$this->addSql('ALTER DATABASE '.$this->container->getParameter('database_name').' CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;'); $this->addSql('ALTER DATABASE '.$this->connection->getParams()['dbname'].' CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;');
$this->addSql('ALTER TABLE '.$this->getTable('annotation').' CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;'); $this->addSql('ALTER TABLE '.$this->getTable('annotation').' CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
$this->addSql('ALTER TABLE '.$this->getTable('entry').' CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;'); $this->addSql('ALTER TABLE '.$this->getTable('entry').' CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;');