-
-
Notifications
You must be signed in to change notification settings - Fork 277
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 #2308 from acelaya-forks/feature/geolocation-updates
Improve how geolocation DB files are downloaded/updated
- Loading branch information
Showing
14 changed files
with
488 additions
and
163 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
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
63 changes: 63 additions & 0 deletions
63
.../config/entities-mappings/Shlinkio.Shlink.Core.Geolocation.Entity.GeolocationDbUpdate.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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shlinkio\Shlink\Core; | ||
|
||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; | ||
use Doctrine\ORM\Mapping\Builder\FieldBuilder; | ||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType; | ||
use Shlinkio\Shlink\Core\Geolocation\Entity\GeolocationDbUpdateStatus; | ||
|
||
return static function (ClassMetadata $metadata, array $emConfig): void { | ||
$builder = new ClassMetadataBuilder($metadata); | ||
|
||
$builder->setTable(determineTableName('geolocation_db_updates', $emConfig)); | ||
|
||
$builder->createField('id', Types::BIGINT) | ||
->columnName('id') | ||
->makePrimaryKey() | ||
->generatedValue('IDENTITY') | ||
->option('unsigned', true) | ||
->build(); | ||
|
||
$builder->createField('dateCreated', ChronosDateTimeType::CHRONOS_DATETIME) | ||
->columnName('date_created') | ||
->build(); | ||
|
||
$builder->createField('dateUpdated', ChronosDateTimeType::CHRONOS_DATETIME) | ||
->columnName('date_updated') | ||
->nullable() | ||
->build(); | ||
|
||
(new FieldBuilder($builder, [ | ||
'fieldName' => 'status', | ||
'type' => Types::STRING, | ||
'enumType' => GeolocationDbUpdateStatus::class, | ||
]))->columnName('status') | ||
->length(128) | ||
->build(); | ||
|
||
fieldWithUtf8Charset($builder->createField('error', Types::STRING), $emConfig) | ||
->columnName('error') | ||
->length(1024) | ||
->nullable() | ||
->build(); | ||
|
||
fieldWithUtf8Charset($builder->createField('reason', Types::STRING), $emConfig) | ||
->columnName('reason') | ||
->length(1024) | ||
->build(); | ||
|
||
fieldWithUtf8Charset($builder->createField('filesystemId', Types::STRING), $emConfig) | ||
->columnName('filesystem_id') | ||
->length(512) | ||
->build(); | ||
|
||
// Index on date_updated, as we'll usually sort the query by this field | ||
$builder->addIndex(['date_updated'], 'IDX_geolocation_date_updated'); | ||
// Index on filesystem_id, as we'll usually filter the query by this field | ||
$builder->addIndex(['filesystem_id'], 'IDX_geolocation_status_filesystem'); | ||
}; |
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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShlinkMigrations; | ||
|
||
use Doctrine\DBAL\Platforms\MySQLPlatform; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\Migrations\AbstractMigration; | ||
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType; | ||
|
||
/** | ||
* Create a new table to track geolocation db updates | ||
*/ | ||
final class Version20241212131058 extends AbstractMigration | ||
{ | ||
private const string TABLE_NAME = 'geolocation_db_updates'; | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->skipIf($schema->hasTable(self::TABLE_NAME)); | ||
|
||
$table = $schema->createTable(self::TABLE_NAME); | ||
$table->addColumn('id', Types::BIGINT, [ | ||
'unsigned' => true, | ||
'autoincrement' => true, | ||
'notnull' => true, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
|
||
$table->addColumn('date_created', ChronosDateTimeType::CHRONOS_DATETIME, ['default' => 'CURRENT_TIMESTAMP']); | ||
$table->addColumn('date_updated', ChronosDateTimeType::CHRONOS_DATETIME, ['default' => 'CURRENT_TIMESTAMP']); | ||
|
||
$table->addColumn('status', Types::STRING, [ | ||
'length' => 128, | ||
'default' => 'in-progress', // in-progress, success, error | ||
]); | ||
$table->addColumn('filesystem_id', Types::STRING, ['length' => 512]); | ||
|
||
$table->addColumn('reason', Types::STRING, ['length' => 1024]); | ||
$table->addColumn('error', Types::STRING, [ | ||
'length' => 1024, | ||
'default' => null, | ||
'notnull' => false, | ||
]); | ||
|
||
// Index on date_updated, as we'll usually sort the query by this field | ||
$table->addIndex(['date_updated'], 'IDX_geolocation_date_updated'); | ||
// Index on filesystem_id, as we'll usually filter the query by this field | ||
$table->addIndex(['filesystem_id'], 'IDX_geolocation_status_filesystem'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->skipIf(! $schema->hasTable(self::TABLE_NAME)); | ||
$schema->dropTable(self::TABLE_NAME); | ||
} | ||
|
||
public function isTransactional(): bool | ||
{ | ||
return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); | ||
} | ||
} |
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
Oops, something went wrong.