Added import_source column in ShortUrls

This commit is contained in:
Alejandro Celaya 2020-10-23 12:59:39 +02:00
parent 33d3837795
commit 554d9b092f
3 changed files with 40 additions and 2 deletions

View file

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace ShlinkMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20201023090929 extends AbstractMigration
{
private const IMPORT_SOURCE_COLUMN = 'import_source';
public function up(Schema $schema): void
{
$shortUrls = $schema->getTable('short_urls');
$this->skipIf($shortUrls->hasColumn(self::IMPORT_SOURCE_COLUMN));
$shortUrls->addColumn(self::IMPORT_SOURCE_COLUMN, Types::STRING, [
'length' => 255,
'notnull' => false,
]);
}
public function down(Schema $schema): void
{
$shortUrls = $schema->getTable('short_urls');
$this->skipIf(! $shortUrls->hasColumn(self::IMPORT_SOURCE_COLUMN));
$shortUrls->dropColumn(self::IMPORT_SOURCE_COLUMN);
}
}

View file

@ -51,6 +51,11 @@ return static function (ClassMetadata $metadata, array $emConfig): void {
->nullable()
->build();
$builder->createField('importSource', Types::STRING)
->columnName('import_source')
->nullable()
->build();
$builder->createOneToMany('visits', Entity\Visit::class)
->mappedBy('shortUrl')
->fetchExtraLazy()

View file

@ -35,7 +35,7 @@ class ShortUrl extends AbstractEntity
private ?Domain $domain = null;
private bool $customSlugWasProvided;
private int $shortCodeLength;
private ?string $source = null;
private ?string $importSource = null;
public function __construct(
string $longUrl,
@ -72,7 +72,7 @@ class ShortUrl extends AbstractEntity
}
$instance = new self($url->longUrl(), ShortUrlMeta::fromRawData($meta), $domainResolver);
$instance->source = $source;
$instance->importSource = $source;
$instance->dateCreated = Chronos::instance($url->createdAt());
return $instance;