mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 15:13:59 -06:00
Updated entity mappings so that schema an table prefixes can be eventually provided
This commit is contained in:
parent
96350c8b8f
commit
bd2f488e2c
@ -8,10 +8,10 @@ use Doctrine\DBAL\Types\Types;
|
|||||||
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
|
|
||||||
return static function (ClassMetadata $metadata): void {
|
return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||||
$builder = new ClassMetadataBuilder($metadata);
|
$builder = new ClassMetadataBuilder($metadata);
|
||||||
|
|
||||||
$builder->setTable('domains');
|
$builder->setTable(determineTableName('domains', $emConfig));
|
||||||
|
|
||||||
$builder->createField('id', Types::BIGINT)
|
$builder->createField('id', Types::BIGINT)
|
||||||
->columnName('id')
|
->columnName('id')
|
||||||
|
@ -9,10 +9,10 @@ use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
|||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType;
|
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType;
|
||||||
|
|
||||||
return static function (ClassMetadata $metadata): void {
|
return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||||
$builder = new ClassMetadataBuilder($metadata);
|
$builder = new ClassMetadataBuilder($metadata);
|
||||||
|
|
||||||
$builder->setTable('short_urls')
|
$builder->setTable(determineTableName('short_urls', $emConfig))
|
||||||
->setCustomRepositoryClass(Repository\ShortUrlRepository::class);
|
->setCustomRepositoryClass(Repository\ShortUrlRepository::class);
|
||||||
|
|
||||||
$builder->createField('id', Types::BIGINT)
|
$builder->createField('id', Types::BIGINT)
|
||||||
@ -57,7 +57,7 @@ return static function (ClassMetadata $metadata): void {
|
|||||||
->build();
|
->build();
|
||||||
|
|
||||||
$builder->createManyToMany('tags', Entity\Tag::class)
|
$builder->createManyToMany('tags', Entity\Tag::class)
|
||||||
->setJoinTable('short_urls_in_tags')
|
->setJoinTable(determineTableName('short_urls_in_tags', $emConfig))
|
||||||
->addInverseJoinColumn('tag_id', 'id', true, false, 'CASCADE')
|
->addInverseJoinColumn('tag_id', 'id', true, false, 'CASCADE')
|
||||||
->addJoinColumn('short_url_id', 'id', true, false, 'CASCADE')
|
->addJoinColumn('short_url_id', 'id', true, false, 'CASCADE')
|
||||||
->build();
|
->build();
|
||||||
|
@ -8,10 +8,10 @@ use Doctrine\DBAL\Types\Types;
|
|||||||
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
|
|
||||||
return static function (ClassMetadata $metadata): void {
|
return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||||
$builder = new ClassMetadataBuilder($metadata);
|
$builder = new ClassMetadataBuilder($metadata);
|
||||||
|
|
||||||
$builder->setTable('tags')
|
$builder->setTable(determineTableName('tags', $emConfig))
|
||||||
->setCustomRepositoryClass(Repository\TagRepository::class);
|
->setCustomRepositoryClass(Repository\TagRepository::class);
|
||||||
|
|
||||||
$builder->createField('id', Types::BIGINT)
|
$builder->createField('id', Types::BIGINT)
|
||||||
|
@ -10,10 +10,10 @@ use Doctrine\ORM\Mapping\ClassMetadata;
|
|||||||
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType;
|
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType;
|
||||||
use Shlinkio\Shlink\Core\Model\Visitor;
|
use Shlinkio\Shlink\Core\Model\Visitor;
|
||||||
|
|
||||||
return static function (ClassMetadata $metadata): void {
|
return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||||
$builder = new ClassMetadataBuilder($metadata);
|
$builder = new ClassMetadataBuilder($metadata);
|
||||||
|
|
||||||
$builder->setTable('visits')
|
$builder->setTable(determineTableName('visits', $emConfig))
|
||||||
->setCustomRepositoryClass(Repository\VisitRepository::class);
|
->setCustomRepositoryClass(Repository\VisitRepository::class);
|
||||||
|
|
||||||
$builder->createField('id', Types::BIGINT)
|
$builder->createField('id', Types::BIGINT)
|
||||||
|
@ -8,10 +8,10 @@ use Doctrine\DBAL\Types\Types;
|
|||||||
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
|
|
||||||
return static function (ClassMetadata $metadata): void {
|
return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||||
$builder = new ClassMetadataBuilder($metadata);
|
$builder = new ClassMetadataBuilder($metadata);
|
||||||
|
|
||||||
$builder->setTable('visit_locations');
|
$builder->setTable(determineTableName('visit_locations', $emConfig));
|
||||||
|
|
||||||
$builder->createField('id', Types::BIGINT)
|
$builder->createField('id', Types::BIGINT)
|
||||||
->columnName('id')
|
->columnName('id')
|
||||||
|
@ -8,6 +8,8 @@ use Cake\Chronos\Chronos;
|
|||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use PUGX\Shortid\Factory as ShortIdFactory;
|
use PUGX\Shortid\Factory as ShortIdFactory;
|
||||||
|
|
||||||
|
use function sprintf;
|
||||||
|
|
||||||
function generateRandomShortCode(int $length = 5): string
|
function generateRandomShortCode(int $length = 5): string
|
||||||
{
|
{
|
||||||
static $shortIdFactory;
|
static $shortIdFactory;
|
||||||
@ -39,3 +41,15 @@ function parseDateField($date): ?Chronos
|
|||||||
|
|
||||||
return Chronos::parse($date);
|
return Chronos::parse($date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function determineTableName(string $tableName, array $emConfig = []): string
|
||||||
|
{
|
||||||
|
$schema = $emConfig['connection']['schema'] ?? null;
|
||||||
|
// $tablePrefix = $emConfig['connection']['table_prefix'] ?? null; // TODO
|
||||||
|
|
||||||
|
if ($schema === null) {
|
||||||
|
return $tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf('%s.%s', $schema, $tableName);
|
||||||
|
}
|
||||||
|
@ -9,10 +9,12 @@ use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
|||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType;
|
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType;
|
||||||
|
|
||||||
return static function (ClassMetadata $metadata): void {
|
use function Shlinkio\Shlink\Core\determineTableName;
|
||||||
|
|
||||||
|
return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||||
$builder = new ClassMetadataBuilder($metadata);
|
$builder = new ClassMetadataBuilder($metadata);
|
||||||
|
|
||||||
$builder->setTable('api_keys');
|
$builder->setTable(determineTableName('api_keys', $emConfig));
|
||||||
|
|
||||||
$builder->createField('id', Types::BIGINT)
|
$builder->createField('id', Types::BIGINT)
|
||||||
->makePrimaryKey()
|
->makePrimaryKey()
|
||||||
@ -31,5 +33,5 @@ return static function (ClassMetadata $metadata): void {
|
|||||||
->build();
|
->build();
|
||||||
|
|
||||||
$builder->createField('enabled', Types::BOOLEAN)
|
$builder->createField('enabled', Types::BOOLEAN)
|
||||||
->build();
|
->build();
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,5 @@ parameters:
|
|||||||
checkMissingIterableValueType: false
|
checkMissingIterableValueType: false
|
||||||
checkGenericClassInNonGenericObjectType: false
|
checkGenericClassInNonGenericObjectType: false
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
- '#Undefined variable: \$metadata#'
|
|
||||||
- '#AbstractQuery::setParameters()#'
|
- '#AbstractQuery::setParameters()#'
|
||||||
- '#mustRun()#'
|
- '#mustRun()#'
|
||||||
|
Loading…
Reference in New Issue
Block a user