-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #500 from acelaya-forks/feature/multiple-domains
Feature/multiple domains
- Loading branch information
Showing
42 changed files
with
748 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ShlinkMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\Schema\SchemaException; | ||
use Doctrine\DBAL\Types\Type; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20190930165521 extends AbstractMigration | ||
{ | ||
/** | ||
* @throws SchemaException | ||
*/ | ||
public function up(Schema $schema): void | ||
{ | ||
$shortUrls = $schema->getTable('short_urls'); | ||
if ($shortUrls->hasColumn('domain_id')) { | ||
return; | ||
} | ||
|
||
$domains = $schema->createTable('domains'); | ||
$domains->addColumn('id', Type::BIGINT, [ | ||
'unsigned' => true, | ||
'autoincrement' => true, | ||
'notnull' => true, | ||
]); | ||
$domains->addColumn('authority', Type::STRING, [ | ||
'length' => 512, | ||
'notnull' => true, | ||
]); | ||
$domains->addUniqueIndex(['authority']); | ||
$domains->setPrimaryKey(['id']); | ||
|
||
$shortUrls->addColumn('domain_id', Type::BIGINT, [ | ||
'unsigned' => true, | ||
'notnull' => false, | ||
]); | ||
$shortUrls->addForeignKeyConstraint('domains', ['domain_id'], ['id'], [ | ||
'onDelete' => 'RESTRICT', | ||
'onUpdate' => 'RESTRICT', | ||
]); | ||
} | ||
|
||
/** | ||
* @throws SchemaException | ||
*/ | ||
public function down(Schema $schema): void | ||
{ | ||
$schema->getTable('short_urls')->dropColumn('domain_id'); | ||
$schema->dropTable('domains'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ShlinkMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Index; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\Schema\SchemaException; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
use function array_reduce; | ||
|
||
final class Version20191001201532 extends AbstractMigration | ||
{ | ||
/** | ||
* @throws SchemaException | ||
*/ | ||
public function up(Schema $schema): void | ||
{ | ||
$shortUrls = $schema->getTable('short_urls'); | ||
if ($shortUrls->hasIndex('unique_short_code_plus_domain')) { | ||
return; | ||
} | ||
|
||
/** @var Index|null $shortCodesIndex */ | ||
$shortCodesIndex = array_reduce($shortUrls->getIndexes(), function (?Index $found, Index $current) { | ||
[$column] = $current->getColumns(); | ||
return $column === 'short_code' ? $current : $found; | ||
}); | ||
if ($shortCodesIndex === null) { | ||
return; | ||
} | ||
|
||
$shortUrls->dropIndex($shortCodesIndex->getName()); | ||
$shortUrls->addUniqueIndex(['short_code', 'domain_id'], 'unique_short_code_plus_domain'); | ||
} | ||
|
||
/** | ||
* @throws SchemaException | ||
*/ | ||
public function down(Schema $schema): void | ||
{ | ||
$shortUrls = $schema->getTable('short_urls'); | ||
|
||
$shortUrls->dropIndex('unique_short_code_plus_domain'); | ||
$shortUrls->addUniqueIndex(['short_code']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
module/Core/config/entities-mappings/Shlinkio.Shlink.Core.Entity.Domain.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Shlinkio\Shlink\Core; | ||
|
||
use Doctrine\DBAL\Types\Type; | ||
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; | ||
use Doctrine\ORM\Mapping\ClassMetadata; // @codingStandardsIgnoreLine | ||
|
||
/** @var $metadata ClassMetadata */ | ||
$builder = new ClassMetadataBuilder($metadata); | ||
|
||
$builder->setTable('domains'); | ||
|
||
$builder->createField('id', Type::BIGINT) | ||
->columnName('id') | ||
->makePrimaryKey() | ||
->generatedValue('IDENTITY') | ||
->option('unsigned', true) | ||
->build(); | ||
|
||
$builder->createField('authority', Type::STRING) | ||
->unique() | ||
->build(); |
Oops, something went wrong.