|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ShlinkMigrations; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
8
|
|
|
use Doctrine\DBAL\Types\Types; |
|
9
|
|
|
use Doctrine\Migrations\AbstractMigration; |
|
10
|
|
|
|
|
11
|
|
|
final class Version20200323190014 extends AbstractMigration |
|
12
|
|
|
{ |
|
13
|
|
|
public function up(Schema $schema): void |
|
14
|
|
|
{ |
|
15
|
|
|
$visitLocations = $schema->getTable('visit_locations'); |
|
16
|
|
|
$this->skipIf($visitLocations->hasColumn('is_empty')); |
|
17
|
|
|
|
|
18
|
|
|
$visitLocations->addColumn('is_empty', Types::BOOLEAN, ['default' => false]); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function postUp(Schema $schema): void |
|
22
|
|
|
{ |
|
23
|
|
|
$qb = $this->connection->createQueryBuilder(); |
|
24
|
|
|
$qb->update('visit_locations') |
|
25
|
|
|
->set('is_empty', true) |
|
|
|
|
|
|
26
|
|
|
->where($qb->expr()->eq('country_code', ':empty')) |
|
27
|
|
|
->andWhere($qb->expr()->eq('country_name', ':empty')) |
|
28
|
|
|
->andWhere($qb->expr()->eq('region_name', ':empty')) |
|
29
|
|
|
->andWhere($qb->expr()->eq('city_name', ':empty')) |
|
30
|
|
|
->andWhere($qb->expr()->eq('timezone', ':empty')) |
|
31
|
|
|
->andWhere($qb->expr()->eq('lat', 0)) |
|
32
|
|
|
->andWhere($qb->expr()->eq('lon', 0)) |
|
33
|
|
|
->setParameter('empty', '') |
|
34
|
|
|
->execute(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function down(Schema $schema): void |
|
38
|
|
|
{ |
|
39
|
|
|
$visitLocations = $schema->getTable('visit_locations'); |
|
40
|
|
|
$this->skipIf(!$visitLocations->hasColumn('is_empty')); |
|
41
|
|
|
|
|
42
|
|
|
$visitLocations->dropColumn('is_empty'); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|