Fixed short codes DB length too short

This commit is contained in:
Alejandro Celaya 2018-08-01 20:40:24 +02:00
parent a79c1f580e
commit 3883ed15c4
3 changed files with 46 additions and 2 deletions

View File

@ -0,0 +1,44 @@
<?php declare(strict_types=1);
namespace ShlinkMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20180801183328 extends AbstractMigration
{
private const NEW_SIZE = 255;
private const OLD_SIZE = 10;
/**
* @param Schema $schema
* @throws SchemaException
*/
public function up(Schema $schema) : void
{
$this->setSize($schema, self::NEW_SIZE);
}
/**
* @param Schema $schema
* @throws SchemaException
*/
public function down(Schema $schema) : void
{
$this->setSize($schema, self::OLD_SIZE);
}
/**
* @param Schema $schema
* @param int $size
* @throws SchemaException
*/
private function setSize(Schema $schema, int $size): void
{
$schema->getTable('short_urls')->getColumn('short_code')->setLength($size);
}
}

View File

@ -29,7 +29,7 @@ class ShortUrl extends AbstractEntity implements \JsonSerializable
* name="short_code",
* type="string",
* nullable=false,
* length=10,
* length=255,
* unique=true
* )
*/

View File

@ -38,7 +38,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
$bar = new ShortUrl();
$bar->setOriginalUrl('bar')
->setShortCode('bar')
->setShortCode('bar_very_long_text')
->setValidSince((new \DateTime())->add(new \DateInterval('P1M')));
$this->getEntityManager()->persist($bar);