diff --git a/CHANGELOG.md b/CHANGELOG.md index 90f4acd1..7d2459b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,30 @@ 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). +## [Unreleased] + +#### Added + +* *Nothing* + +#### Changed + +* *Nothing* + +#### Deprecated + +* *Nothing* + +#### Removed + +* *Nothing* + +#### Fixed + +* [#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. + + ## 2.0.0 - 2020-01-08 #### Added diff --git a/data/migrations/Version20200105165647.php b/data/migrations/Version20200105165647.php index 24b9f984..6367f440 100644 --- a/data/migrations/Version20200105165647.php +++ b/data/migrations/Version20200105165647.php @@ -9,18 +9,35 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Types\Types; use Doctrine\Migrations\AbstractMigration; +use function Functional\some; + final class Version20200105165647 extends AbstractMigration { private const COLUMNS = ['lat' => 'latitude', 'lon' => 'longitude']; + /** + * @throws DBALException + */ public function preUp(Schema $schema): void { + $visitLocations = $schema->getTable('visit_locations'); + $this->skipIf(some( + self::COLUMNS, + fn (string $v, string $newColName) => $visitLocations->hasColumn($newColName), + ), 'New columns already exist'); + foreach (self::COLUMNS as $columnName) { $qb = $this->connection->createQueryBuilder(); $qb->update('visit_locations') - ->set($columnName, '"0"') - ->where($columnName . '=""') - ->orWhere($columnName . ' IS NULL') + ->set($columnName, ':zeroValue') + ->where($qb->expr()->orX( + $qb->expr()->eq($columnName, ':emptyString'), + $qb->expr()->isNull($columnName), + )) + ->setParameters([ + 'zeroValue' => '0', + 'emptyString' => '', + ]) ->execute(); } } @@ -33,16 +50,24 @@ final class Version20200105165647 extends AbstractMigration $visitLocations = $schema->getTable('visit_locations'); foreach (self::COLUMNS as $newName => $oldName) { - $visitLocations->addColumn($newName, Types::FLOAT); + $visitLocations->addColumn($newName, Types::FLOAT, [ + 'default' => '0.0', + ]); } } + /** + * @throws DBALException + */ public function postUp(Schema $schema): void { + $platformName = $this->connection->getDatabasePlatform()->getName(); + $castType = $platformName === 'postgres' ? 'DOUBLE PRECISION' : 'DECIMAL(9,2)'; + foreach (self::COLUMNS as $newName => $oldName) { $qb = $this->connection->createQueryBuilder(); $qb->update('visit_locations') - ->set($newName, $oldName) + ->set($newName, 'CAST(' . $oldName . ' AS ' . $castType . ')') ->execute(); } } diff --git a/data/migrations/Version20200106215144.php b/data/migrations/Version20200106215144.php index 8969441b..e7a2c31a 100644 --- a/data/migrations/Version20200106215144.php +++ b/data/migrations/Version20200106215144.php @@ -9,6 +9,8 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Types\Types; use Doctrine\Migrations\AbstractMigration; +use function Functional\none; + final class Version20200106215144 extends AbstractMigration { private const COLUMNS = ['latitude', 'longitude']; @@ -19,6 +21,10 @@ final class Version20200106215144 extends AbstractMigration public function up(Schema $schema): void { $visitLocations = $schema->getTable('visit_locations'); + $this->skipIf(none( + self::COLUMNS, + fn (string $oldColName) => $visitLocations->hasColumn($oldColName), + ), 'Old columns do not exist'); foreach (self::COLUMNS as $colName) { $visitLocations->dropColumn($colName);