From 96bb0321eb69e0c78c1bd6fbdfeff8b2fed04b9a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 10 Jan 2020 19:08:23 +0100 Subject: [PATCH] Updated casting type so that it is dynamic --- data/migrations/Version20200105165647.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/data/migrations/Version20200105165647.php b/data/migrations/Version20200105165647.php index 9fa6a918..6367f440 100644 --- a/data/migrations/Version20200105165647.php +++ b/data/migrations/Version20200105165647.php @@ -56,12 +56,18 @@ final class Version20200105165647 extends AbstractMigration } } + /** + * @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, 'CAST(' . $oldName . ' AS DOUBLE PRECISION)') + ->set($newName, 'CAST(' . $oldName . ' AS ' . $castType . ')') ->execute(); } }