2016-08-19 15:51:34 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
2016-08-19 15:51:34 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
2016-08-19 15:51:34 +03:00
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
2019-03-09 20:45:58 +03:00
|
|
|
use Doctrine\DBAL\Schema\SchemaException;
|
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
2016-08-19 15:51:34 +03:00
|
|
|
|
2022-01-10 15:04:16 +03:00
|
|
|
use function is_subclass_of;
|
2022-01-10 14:05:01 +03:00
|
|
|
|
2016-08-19 15:51:34 +03:00
|
|
|
/**
|
|
|
|
* Auto-generated Migration: Please modify to your needs!
|
|
|
|
*/
|
|
|
|
class Version20160819142757 extends AbstractMigration
|
|
|
|
{
|
|
|
|
/**
|
2021-03-12 13:52:43 +03:00
|
|
|
* @throws Exception
|
2019-03-09 20:45:58 +03:00
|
|
|
* @throws SchemaException
|
2016-08-19 15:51:34 +03:00
|
|
|
*/
|
2019-03-09 20:45:58 +03:00
|
|
|
public function up(Schema $schema): void
|
2016-08-19 15:51:34 +03:00
|
|
|
{
|
2022-01-10 15:04:16 +03:00
|
|
|
$platformClass = $this->connection->getDatabasePlatform();
|
2016-08-19 15:51:34 +03:00
|
|
|
$table = $schema->getTable('short_urls');
|
|
|
|
$column = $table->getColumn('short_code');
|
|
|
|
|
2022-01-10 15:04:16 +03:00
|
|
|
match (true) {
|
|
|
|
is_subclass_of($platformClass, MySQLPlatform::class) => $column
|
|
|
|
->setPlatformOption('charset', 'utf8mb4')
|
|
|
|
->setPlatformOption('collation', 'utf8mb4_bin'),
|
|
|
|
is_subclass_of($platformClass, SqlitePlatform::class) => $column->setPlatformOption('collate', 'BINARY'),
|
2022-01-10 14:05:01 +03:00
|
|
|
default => null,
|
|
|
|
};
|
2016-08-19 15:51:34 +03:00
|
|
|
}
|
|
|
|
|
2019-03-09 20:45:58 +03:00
|
|
|
public function down(Schema $schema): void
|
2016-08-19 15:51:34 +03:00
|
|
|
{
|
2022-01-10 14:05:01 +03:00
|
|
|
// Nothing to roll back
|
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);
|
2016-08-19 15:51:34 +03:00
|
|
|
}
|
|
|
|
}
|