mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-24 21:58:40 +03:00
Merge pull request #612 from acelaya-forks/feature/avoid-nulls
Feature/avoid nulls
This commit is contained in:
commit
b246815529
4 changed files with 60 additions and 6 deletions
|
@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
|
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
|
||||||
|
|
||||||
## [Unreleased]
|
## 2.0.1 - 2020-01-10
|
||||||
|
|
||||||
#### Added
|
#### Added
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
|
||||||
|
|
||||||
* [#607](https://github.com/shlinkio/shlink/issues/607) Added missing info on UPGRADE.md doc.
|
* [#607](https://github.com/shlinkio/shlink/issues/607) Added missing info on UPGRADE.md doc.
|
||||||
* [#610](https://github.com/shlinkio/shlink/issues/610) Fixed use of hardcoded quotes on a database migration which makes it fail on postgres.
|
* [#610](https://github.com/shlinkio/shlink/issues/610) Fixed use of hardcoded quotes on a database migration which makes it fail on postgres.
|
||||||
|
* [#605](https://github.com/shlinkio/shlink/issues/605) Fixed crashes occurring when migrating from old Shlink versions with nullable DB columns that are assigned to non-nullable entity typed props.
|
||||||
|
|
||||||
|
|
||||||
## 2.0.0 - 2020-01-08
|
## 2.0.0 - 2020-01-08
|
||||||
|
|
53
data/migrations/Version20200110182849.php
Normal file
53
data/migrations/Version20200110182849.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace ShlinkMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
use function Functional\each;
|
||||||
|
use function Functional\partial_left;
|
||||||
|
|
||||||
|
final class Version20200110182849 extends AbstractMigration
|
||||||
|
{
|
||||||
|
private const DEFAULT_EMPTY_VALUE = '';
|
||||||
|
private const COLUMN_DEFAULTS_MAP = [
|
||||||
|
'visits' => [
|
||||||
|
'referer',
|
||||||
|
'user_agent',
|
||||||
|
],
|
||||||
|
'visit_locations' => [
|
||||||
|
'timezone',
|
||||||
|
'country_code',
|
||||||
|
'country_name',
|
||||||
|
'region_name',
|
||||||
|
'city_name',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
each(
|
||||||
|
self::COLUMN_DEFAULTS_MAP,
|
||||||
|
fn (array $columns, string $tableName) =>
|
||||||
|
each($columns, partial_left([$this, 'setDefaultValueForColumnInTable'], $tableName)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDefaultValueForColumnInTable(string $tableName, string $columnName): void
|
||||||
|
{
|
||||||
|
$qb = $this->connection->createQueryBuilder();
|
||||||
|
$qb->update($tableName)
|
||||||
|
->set($columnName, ':emptyValue')
|
||||||
|
->setParameter('emptyValue', self::DEFAULT_EMPTY_VALUE)
|
||||||
|
->where($qb->expr()->isNull($columnName))
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// No need (and no way) to undo this migration
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,9 +29,9 @@ class ShortUrl extends AbstractEntity
|
||||||
private Collection $visits;
|
private Collection $visits;
|
||||||
/** @var Collection|Tag[] */
|
/** @var Collection|Tag[] */
|
||||||
private Collection $tags;
|
private Collection $tags;
|
||||||
private ?Chronos $validSince;
|
private ?Chronos $validSince = null;
|
||||||
private ?Chronos $validUntil;
|
private ?Chronos $validUntil = null;
|
||||||
private ?int $maxVisits;
|
private ?int $maxVisits = null;
|
||||||
private ?Domain $domain;
|
private ?Domain $domain;
|
||||||
private bool $customSlugWasProvided;
|
private bool $customSlugWasProvided;
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,10 @@ use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
||||||
|
|
||||||
class Visit extends AbstractEntity implements JsonSerializable
|
class Visit extends AbstractEntity implements JsonSerializable
|
||||||
{
|
{
|
||||||
private string $referer = '';
|
private string $referer;
|
||||||
private Chronos $date;
|
private Chronos $date;
|
||||||
private ?string $remoteAddr = null;
|
private ?string $remoteAddr = null;
|
||||||
private string $userAgent = '';
|
private string $userAgent;
|
||||||
private ShortUrl $shortUrl;
|
private ShortUrl $shortUrl;
|
||||||
private ?VisitLocation $visitLocation = null;
|
private ?VisitLocation $visitLocation = null;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue