Expand "text" length to 303 (artist+' - '+title).

This commit is contained in:
Buster "Silver Eagle" Neece 2020-11-25 16:11:53 -06:00
parent 2085a475de
commit 421425067c
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
2 changed files with 43 additions and 3 deletions

View File

@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace App\Entity\Migration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20201125220258 extends AbstractMigration
{
public function getDescription(): string
{
return 'Expand the length of the "text" field.';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE song_history CHANGE text text VARCHAR(303) DEFAULT NULL');
$this->addSql('ALTER TABLE station_media CHANGE text text VARCHAR(303) DEFAULT NULL');
$this->addSql('ALTER TABLE station_queue CHANGE text text VARCHAR(303) DEFAULT NULL');
}
public function postUp(Schema $schema): void
{
$this->connection->executeQuery('UPDATE station_media SET text=CONCAT(artist, \' - \', title)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE song_history CHANGE text text VARCHAR(150) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_general_ci`');
$this->addSql('ALTER TABLE station_media CHANGE text text VARCHAR(150) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_general_ci`');
$this->addSql('ALTER TABLE station_queue CHANGE text text VARCHAR(150) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_general_ci`');
}
}

View File

@ -17,7 +17,7 @@ trait HasSongFields
protected $song_id;
/**
* @ORM\Column(name="text", type="string", length=150, nullable=true)
* @ORM\Column(name="text", type="string", length=303, nullable=true)
* @var string|null
*/
protected $text;
@ -36,7 +36,7 @@ trait HasSongFields
public function setSong(SongInterface $song): void
{
$this->title = $this->truncateString($song->getTitle(), 150);
$this->title = $this->truncateString($song->getTitle(), 303);
$this->artist = $this->truncateString($song->getArtist(), 150);
$this->text = $this->truncateString($song->getText(), 150);
@ -68,7 +68,7 @@ trait HasSongFields
public function setText(?string $text): void
{
$oldText = $this->text;
$this->text = $this->truncateString($text, 150);
$this->text = $this->truncateString($text, 303);
if (0 !== strcmp($oldText, $this->text)) {
$this->updateSongId();