2020-01-06 15:57:10 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkMigrations;
|
|
|
|
|
2021-03-12 04:52:43 -06:00
|
|
|
use Doctrine\DBAL\Exception;
|
2022-01-10 05:05:01 -06:00
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
2020-01-06 15:57:10 -06:00
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
2023-11-30 07:34:21 -06:00
|
|
|
use Doctrine\DBAL\Schema\Table;
|
2020-01-06 15:57:10 -06:00
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
|
|
|
|
final class Version20200106215144 extends AbstractMigration
|
|
|
|
{
|
|
|
|
private const COLUMNS = ['latitude', 'longitude'];
|
|
|
|
|
|
|
|
/**
|
2021-03-12 04:52:43 -06:00
|
|
|
* @throws Exception
|
2020-01-06 15:57:10 -06:00
|
|
|
*/
|
|
|
|
public function up(Schema $schema): void
|
|
|
|
{
|
|
|
|
$visitLocations = $schema->getTable('visit_locations');
|
2023-11-30 07:34:21 -06:00
|
|
|
$this->skipIf($this->oldColumnsDoNotExist($visitLocations), 'Old columns do not exist');
|
2020-01-06 15:57:10 -06:00
|
|
|
|
|
|
|
foreach (self::COLUMNS as $colName) {
|
|
|
|
$visitLocations->dropColumn($colName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-30 07:34:21 -06:00
|
|
|
public function oldColumnsDoNotExist(Table $visitLocations): bool
|
|
|
|
{
|
|
|
|
foreach (self::COLUMNS as $oldColName) {
|
|
|
|
if ($visitLocations->hasColumn($oldColName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-06 15:57:10 -06:00
|
|
|
/**
|
2021-03-12 04:52:43 -06:00
|
|
|
* @throws Exception
|
2020-01-06 15:57:10 -06: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 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-01-06 15:57:10 -06:00
|
|
|
}
|