Switch to utf8mb4_bin collation to resolve media import issues.

This commit is contained in:
Buster "Silver Eagle" Neece 2018-04-25 00:18:02 -05:00
parent 8e42439179
commit ecbae6d072
1 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,47 @@
<?php declare(strict_types = 1);
namespace Migration;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20180425050351 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->changeCharset('utf8mb4', 'utf8mb4_bin');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->changeCharset('utf8mb4', 'utf8mb4_unicode_ci');
}
protected function changeCharset($charset, $collate)
{
$this->addSql([
'ALTER TABLE `station_media` DROP FOREIGN KEY FK_32AADE3AA0BDB2F3',
'ALTER TABLE `song_history` DROP FOREIGN KEY FK_2AD16164A0BDB2F3',
'ALTER TABLE `station_media` CONVERT TO CHARACTER SET '.$charset.' COLLATE '.$collate,
'ALTER TABLE `song_history` CONVERT TO CHARACTER SET '.$charset.' COLLATE '.$collate,
'ALTER TABLE `songs` CONVERT TO CHARACTER SET '.$charset.' COLLATE '.$collate,
'ALTER TABLE `song_history` ADD CONSTRAINT FK_2AD16164A0BDB2F3 FOREIGN KEY (song_id) REFERENCES songs (id) ON DELETE CASCADE',
'ALTER TABLE `station_media` ADD CONSTRAINT FK_32AADE3AA0BDB2F3 FOREIGN KEY (song_id) REFERENCES songs (id) ON DELETE SET NULL',
]);
}
}