Version20200323190014.php 1.6 KB

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