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