2021-01-02 21:35:16 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkMigrations;
|
|
|
|
|
2022-01-10 14:05:01 +03:00
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
2021-01-02 21:35:16 +03:00
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
|
|
|
|
final class Version20210102174433 extends AbstractMigration
|
|
|
|
{
|
|
|
|
private const TABLE_NAME = 'api_key_roles';
|
|
|
|
|
|
|
|
public function up(Schema $schema): void
|
|
|
|
{
|
|
|
|
$this->skipIf($schema->hasTable(self::TABLE_NAME));
|
|
|
|
|
|
|
|
$table = $schema->createTable(self::TABLE_NAME);
|
|
|
|
$table->addColumn('id', Types::BIGINT, [
|
|
|
|
'unsigned' => true,
|
|
|
|
'autoincrement' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
|
|
|
$table->setPrimaryKey(['id']);
|
|
|
|
|
|
|
|
$table->addColumn('role_name', Types::STRING, [
|
2021-01-18 19:14:46 +03:00
|
|
|
'length' => 255,
|
2021-01-02 21:35:16 +03:00
|
|
|
'notnull' => true,
|
|
|
|
]);
|
|
|
|
$table->addColumn('meta', Types::JSON, [
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$table->addColumn('api_key_id', Types::BIGINT, [
|
|
|
|
'unsigned' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
|
|
|
$table->addForeignKeyConstraint('api_keys', ['api_key_id'], ['id'], [
|
|
|
|
'onDelete' => 'CASCADE',
|
|
|
|
'onUpdate' => 'RESTRICT',
|
|
|
|
]);
|
|
|
|
$table->addUniqueIndex(['role_name', 'api_key_id'], 'UQ_role_plus_api_key');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function down(Schema $schema): void
|
|
|
|
{
|
|
|
|
$this->skipIf(! $schema->hasTable(self::TABLE_NAME));
|
|
|
|
$schema->getTable(self::TABLE_NAME)->dropIndex('UQ_role_plus_api_key');
|
|
|
|
$schema->dropTable(self::TABLE_NAME);
|
|
|
|
}
|
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
|
|
|
}
|
2021-01-02 21:35:16 +03:00
|
|
|
}
|