2020-03-23 14:37:45 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkMigrations;
|
|
|
|
|
2022-01-10 05:05:01 -06:00
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
2020-03-23 14:37:45 -05:00
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
|
|
|
|
final class Version20200323190014 extends AbstractMigration
|
|
|
|
{
|
|
|
|
public function up(Schema $schema): void
|
|
|
|
{
|
|
|
|
$visitLocations = $schema->getTable('visit_locations');
|
|
|
|
$this->skipIf($visitLocations->hasColumn('is_empty'));
|
|
|
|
|
|
|
|
$visitLocations->addColumn('is_empty', Types::BOOLEAN, ['default' => false]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function postUp(Schema $schema): void
|
|
|
|
{
|
|
|
|
$qb = $this->connection->createQueryBuilder();
|
|
|
|
$qb->update('visit_locations')
|
2020-03-29 02:05:04 -05:00
|
|
|
->set('is_empty', ':isEmpty')
|
|
|
|
->where($qb->expr()->eq('country_code', ':emptyString'))
|
|
|
|
->andWhere($qb->expr()->eq('country_name', ':emptyString'))
|
|
|
|
->andWhere($qb->expr()->eq('region_name', ':emptyString'))
|
|
|
|
->andWhere($qb->expr()->eq('city_name', ':emptyString'))
|
|
|
|
->andWhere($qb->expr()->eq('timezone', ':emptyString'))
|
2020-03-23 14:37:45 -05:00
|
|
|
->andWhere($qb->expr()->eq('lat', 0))
|
|
|
|
->andWhere($qb->expr()->eq('lon', 0))
|
2020-03-29 02:05:04 -05:00
|
|
|
->setParameter('isEmpty', true)
|
|
|
|
->setParameter('emptyString', '')
|
2022-01-10 05:05:01 -06:00
|
|
|
->executeStatement();
|
2020-03-23 14:37:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function down(Schema $schema): void
|
|
|
|
{
|
|
|
|
$visitLocations = $schema->getTable('visit_locations');
|
|
|
|
$this->skipIf(!$visitLocations->hasColumn('is_empty'));
|
|
|
|
|
|
|
|
$visitLocations->dropColumn('is_empty');
|
|
|
|
}
|
2021-10-23 09:02:29 -05:00
|
|
|
|
|
|
|
public function isTransactional(): bool
|
|
|
|
{
|
2022-01-10 05:05:01 -06:00
|
|
|
return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform);
|
2021-10-23 09:02:29 -05:00
|
|
|
}
|
2020-03-23 14:37:45 -05:00
|
|
|
}
|