2018-12-16 14:08:03 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2018-12-16 14:08:03 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shlinkio\Shlink\Rest;
|
|
|
|
|
2020-01-07 01:08:14 +03:00
|
|
|
use Doctrine\DBAL\Types\Types;
|
2018-12-16 14:08:03 +03:00
|
|
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
2020-01-29 12:06:42 +03:00
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
2019-08-11 14:44:42 +03:00
|
|
|
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType;
|
2021-01-02 21:35:16 +03:00
|
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKeyRole;
|
2018-12-16 14:08:03 +03:00
|
|
|
|
2020-01-29 12:53:06 +03:00
|
|
|
use function Shlinkio\Shlink\Core\determineTableName;
|
|
|
|
|
|
|
|
return static function (ClassMetadata $metadata, array $emConfig): void {
|
2020-01-29 12:06:42 +03:00
|
|
|
$builder = new ClassMetadataBuilder($metadata);
|
2018-12-16 14:08:03 +03:00
|
|
|
|
2020-01-29 12:53:06 +03:00
|
|
|
$builder->setTable(determineTableName('api_keys', $emConfig));
|
2018-12-16 14:08:03 +03:00
|
|
|
|
2020-01-29 12:06:42 +03:00
|
|
|
$builder->createField('id', Types::BIGINT)
|
|
|
|
->makePrimaryKey()
|
|
|
|
->generatedValue('IDENTITY')
|
|
|
|
->option('unsigned', true)
|
|
|
|
->build();
|
2018-12-16 14:08:03 +03:00
|
|
|
|
2020-01-29 12:06:42 +03:00
|
|
|
$builder->createField('key', Types::STRING)
|
|
|
|
->columnName('`key`')
|
|
|
|
->unique()
|
|
|
|
->build();
|
2018-12-16 14:08:03 +03:00
|
|
|
|
2020-01-29 12:06:42 +03:00
|
|
|
$builder->createField('expirationDate', ChronosDateTimeType::CHRONOS_DATETIME)
|
|
|
|
->columnName('expiration_date')
|
|
|
|
->nullable()
|
|
|
|
->build();
|
2018-12-16 14:08:03 +03:00
|
|
|
|
2020-01-29 12:06:42 +03:00
|
|
|
$builder->createField('enabled', Types::BOOLEAN)
|
2020-01-29 12:53:06 +03:00
|
|
|
->build();
|
2021-01-02 21:35:16 +03:00
|
|
|
|
|
|
|
$builder->createOneToMany('roles', ApiKeyRole::class)
|
|
|
|
->mappedBy('apiKey')
|
2021-01-06 12:59:02 +03:00
|
|
|
->setIndexBy('roleName')
|
|
|
|
->cascadePersist()
|
|
|
|
->orphanRemoval()
|
2021-01-02 21:35:16 +03:00
|
|
|
->build();
|
2020-01-29 12:06:42 +03:00
|
|
|
};
|