mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Ensured latitude and longitude are set as float in DB
This commit is contained in:
parent
2e0f8067aa
commit
7748dd7cef
52
data/migrations/Version20200105165647.php
Normal file
52
data/migrations/Version20200105165647.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace ShlinkMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\DBALException;
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\DBAL\Types\Type;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20200105165647 extends AbstractMigration
|
||||||
|
{
|
||||||
|
private const COLUMNS = ['latitude', 'longitude'];
|
||||||
|
|
||||||
|
public function preUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
foreach (self::COLUMNS as $columnName) {
|
||||||
|
$qb = $this->connection->createQueryBuilder();
|
||||||
|
$qb->update('visit_locations')
|
||||||
|
->set($columnName, '"0"')
|
||||||
|
->where($columnName . '=""')
|
||||||
|
->orWhere($columnName . ' IS NULL')
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws DBALException
|
||||||
|
*/
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$visitLocations = $schema->getTable('visit_locations');
|
||||||
|
|
||||||
|
foreach (self::COLUMNS as $columnName) {
|
||||||
|
$visitLocations->getColumn($columnName)->setType(Type::getType(Types::FLOAT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws DBALException
|
||||||
|
*/
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$visitLocations = $schema->getTable('visit_locations');
|
||||||
|
|
||||||
|
foreach (self::COLUMNS as $columnName) {
|
||||||
|
$visitLocations->getColumn($columnName)->setType(Type::getType(Types::STRING));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -25,8 +25,6 @@ $columns = [
|
|||||||
'country_name' => 'countryName',
|
'country_name' => 'countryName',
|
||||||
'region_name' => 'regionName',
|
'region_name' => 'regionName',
|
||||||
'city_name' => 'cityName',
|
'city_name' => 'cityName',
|
||||||
'latitude' => 'latitude',
|
|
||||||
'longitude' => 'longitude',
|
|
||||||
'timezone' => 'timezone',
|
'timezone' => 'timezone',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -36,3 +34,13 @@ foreach ($columns as $columnName => $fieldName) {
|
|||||||
->nullable()
|
->nullable()
|
||||||
->build();
|
->build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$builder->createField('latitude', Type::FLOAT)
|
||||||
|
->columnName('latitude')
|
||||||
|
->nullable()
|
||||||
|
->build();
|
||||||
|
|
||||||
|
$builder->createField('longitude', Type::FLOAT)
|
||||||
|
->columnName('longitude')
|
||||||
|
->nullable()
|
||||||
|
->build();
|
||||||
|
@ -15,10 +15,10 @@ use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
|||||||
|
|
||||||
class Visit extends AbstractEntity implements JsonSerializable
|
class Visit extends AbstractEntity implements JsonSerializable
|
||||||
{
|
{
|
||||||
private string $referer;
|
private string $referer = '';
|
||||||
private Chronos $date;
|
private Chronos $date;
|
||||||
private ?string $remoteAddr;
|
private ?string $remoteAddr = null;
|
||||||
private string $userAgent;
|
private string $userAgent = '';
|
||||||
private ShortUrl $shortUrl;
|
private ShortUrl $shortUrl;
|
||||||
private ?VisitLocation $visitLocation = null;
|
private ?VisitLocation $visitLocation = null;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user