2020-01-07 00:57:10 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkMigrations;
|
|
|
|
|
2021-03-12 13:52:43 +03:00
|
|
|
use Doctrine\DBAL\Exception;
|
2022-01-10 14:05:01 +03:00
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
2020-01-07 00:57:10 +03:00
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
|
2020-01-10 18:50:43 +03:00
|
|
|
use function Functional\none;
|
|
|
|
|
2020-01-07 00:57:10 +03:00
|
|
|
final class Version20200106215144 extends AbstractMigration
|
|
|
|
{
|
|
|
|
private const COLUMNS = ['latitude', 'longitude'];
|
|
|
|
|
|
|
|
/**
|
2021-03-12 13:52:43 +03:00
|
|
|
* @throws Exception
|
2020-01-07 00:57:10 +03:00
|
|
|
*/
|
|
|
|
public function up(Schema $schema): void
|
|
|
|
{
|
|
|
|
$visitLocations = $schema->getTable('visit_locations');
|
2020-01-10 18:50:43 +03:00
|
|
|
$this->skipIf(none(
|
|
|
|
self::COLUMNS,
|
|
|
|
fn (string $oldColName) => $visitLocations->hasColumn($oldColName),
|
|
|
|
), 'Old columns do not exist');
|
2020-01-07 00:57:10 +03:00
|
|
|
|
|
|
|
foreach (self::COLUMNS as $colName) {
|
|
|
|
$visitLocations->dropColumn($colName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-12 13:52:43 +03:00
|
|
|
* @throws Exception
|
2020-01-07 00:57:10 +03:00
|
|
|
*/
|
|
|
|
public function down(Schema $schema): void
|
|
|
|
{
|
|
|
|
$visitLocations = $schema->getTable('visit_locations');
|
|
|
|
|
|
|
|
foreach (self::COLUMNS as $colName) {
|
|
|
|
$visitLocations->addColumn($colName, Types::STRING, [
|
|
|
|
'notnull' => false,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2021-10-23 17:02:29 +03:00
|
|
|
|
|
|
|
public function isTransactional(): bool
|
|
|
|
{
|
2022-01-10 14:05:01 +03:00
|
|
|
return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform);
|
2021-10-23 17:02:29 +03:00
|
|
|
}
|
2020-01-07 00:57:10 +03:00
|
|
|
}
|