Updated casting type so that it is dynamic

This commit is contained in:
Alejandro Celaya 2020-01-10 19:08:23 +01:00
parent 37f0abf86f
commit 96bb0321eb

View file

@ -56,12 +56,18 @@ final class Version20200105165647 extends AbstractMigration
} }
} }
/**
* @throws DBALException
*/
public function postUp(Schema $schema): void 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) { foreach (self::COLUMNS as $newName => $oldName) {
$qb = $this->connection->createQueryBuilder(); $qb = $this->connection->createQueryBuilder();
$qb->update('visit_locations') $qb->update('visit_locations')
->set($newName, 'CAST(' . $oldName . ' AS DOUBLE PRECISION)') ->set($newName, 'CAST(' . $oldName . ' AS ' . $castType . ')')
->execute(); ->execute();
} }
} }