2020-01-06 15:31:00 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkMigrations;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\DBALException;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
|
|
|
|
final class Version20200105165647 extends AbstractMigration
|
|
|
|
{
|
2020-01-06 15:57:10 -06:00
|
|
|
private const COLUMNS = ['lat' => 'latitude', 'lon' => 'longitude'];
|
2020-01-06 15:31:00 -06:00
|
|
|
|
|
|
|
public function preUp(Schema $schema): void
|
|
|
|
{
|
|
|
|
foreach (self::COLUMNS as $columnName) {
|
|
|
|
$qb = $this->connection->createQueryBuilder();
|
|
|
|
$qb->update('visit_locations')
|
|
|
|
->set($columnName, '"0"')
|
|
|
|
->where($columnName . '=""')
|
|
|
|
->orWhere($columnName . ' IS NULL')
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws DBALException
|
|
|
|
*/
|
|
|
|
public function up(Schema $schema): void
|
|
|
|
{
|
|
|
|
$visitLocations = $schema->getTable('visit_locations');
|
|
|
|
|
2020-01-06 15:57:10 -06:00
|
|
|
foreach (self::COLUMNS as $newName => $oldName) {
|
|
|
|
$visitLocations->addColumn($newName, Types::FLOAT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function postUp(Schema $schema): void
|
|
|
|
{
|
|
|
|
foreach (self::COLUMNS as $newName => $oldName) {
|
|
|
|
$qb = $this->connection->createQueryBuilder();
|
|
|
|
$qb->update('visit_locations')
|
|
|
|
->set($newName, $oldName)
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function preDown(Schema $schema): void
|
|
|
|
{
|
|
|
|
foreach (self::COLUMNS as $newName => $oldName) {
|
|
|
|
$qb = $this->connection->createQueryBuilder();
|
|
|
|
$qb->update('visit_locations')
|
|
|
|
->set($oldName, $newName)
|
|
|
|
->execute();
|
2020-01-06 15:31:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws DBALException
|
|
|
|
*/
|
|
|
|
public function down(Schema $schema): void
|
|
|
|
{
|
|
|
|
$visitLocations = $schema->getTable('visit_locations');
|
|
|
|
|
2020-01-06 15:57:10 -06:00
|
|
|
foreach (self::COLUMNS as $colName => $oldName) {
|
|
|
|
$visitLocations->dropColumn($colName);
|
2020-01-06 15:31:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|