Version20200106215144.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. namespace ShlinkMigrations;
  4. use Doctrine\DBAL\Exception;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\Migrations\AbstractMigration;
  8. use function Functional\none;
  9. final class Version20200106215144 extends AbstractMigration
  10. {
  11. private const COLUMNS = ['latitude', 'longitude'];
  12. /**
  13. * @throws Exception
  14. */
  15. public function up(Schema $schema): void
  16. {
  17. $visitLocations = $schema->getTable('visit_locations');
  18. $this->skipIf(none(
  19. self::COLUMNS,
  20. fn (string $oldColName) => $visitLocations->hasColumn($oldColName),
  21. ), 'Old columns do not exist');
  22. foreach (self::COLUMNS as $colName) {
  23. $visitLocations->dropColumn($colName);
  24. }
  25. }
  26. /**
  27. * @throws Exception
  28. */
  29. public function down(Schema $schema): void
  30. {
  31. $visitLocations = $schema->getTable('visit_locations');
  32. foreach (self::COLUMNS as $colName) {
  33. $visitLocations->addColumn($colName, Types::STRING, [
  34. 'notnull' => false,
  35. ]);
  36. }
  37. }
  38. /**
  39. * @fixme Workaround for https://github.com/doctrine/migrations/issues/1104
  40. */
  41. public function isTransactional(): bool
  42. {
  43. return false;
  44. }
  45. }