2021-01-02 21:35:16 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shlinkio\Shlink\Rest;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
2022-04-23 19:41:16 +03:00
|
|
|
use Doctrine\ORM\Mapping\Builder\FieldBuilder;
|
2021-01-02 21:35:16 +03:00
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
2022-04-23 19:41:16 +03:00
|
|
|
use Shlinkio\Shlink\Rest\ApiKey\Role;
|
2021-01-02 21:35:16 +03:00
|
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
|
|
|
|
|
|
|
use function Shlinkio\Shlink\Core\determineTableName;
|
|
|
|
|
|
|
|
return static function (ClassMetadata $metadata, array $emConfig): void {
|
|
|
|
$builder = new ClassMetadataBuilder($metadata);
|
|
|
|
|
|
|
|
$builder->setTable(determineTableName('api_key_roles', $emConfig));
|
|
|
|
|
|
|
|
$builder->createField('id', Types::BIGINT)
|
|
|
|
->makePrimaryKey()
|
|
|
|
->generatedValue('IDENTITY')
|
|
|
|
->option('unsigned', true)
|
|
|
|
->build();
|
|
|
|
|
2022-04-23 19:41:16 +03:00
|
|
|
(new FieldBuilder($builder, [
|
2023-05-30 10:12:46 +03:00
|
|
|
'fieldName' => 'role',
|
2022-04-23 19:41:16 +03:00
|
|
|
'type' => Types::STRING,
|
|
|
|
'enumType' => Role::class,
|
|
|
|
]))->columnName('role_name')
|
|
|
|
->length(255)
|
|
|
|
->nullable(false)
|
|
|
|
->build();
|
2021-01-02 21:35:16 +03:00
|
|
|
|
|
|
|
$builder->createField('meta', Types::JSON)
|
|
|
|
->columnName('meta')
|
|
|
|
->nullable(false)
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->createManyToOne('apiKey', ApiKey::class)
|
|
|
|
->addJoinColumn('api_key_id', 'id', false, false, 'CASCADE')
|
|
|
|
->cascadePersist()
|
|
|
|
->build();
|
|
|
|
|
|
|
|
$builder->addUniqueConstraint(['role_name', 'api_key_id'], 'UQ_role_plus_api_key');
|
|
|
|
};
|