migrations/Version20260604130000.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Offline lat/long -> country resolution: a spatial table of country boundary polygons queried with
  8.  * ST_Contains, replacing the external geokeo reverse-geocoder for country assignment.
  9.  *
  10.  * Seed it after migrating with: bin/console app:geo:seed-country-boundaries
  11.  */
  12. final class Version20260604130000 extends AbstractMigration
  13. {
  14.     public function getDescription(): string
  15.     {
  16.         return 'Add country_boundaries spatial table for offline lat/long -> country resolution.';
  17.     }
  18.     public function up(Schema $schema): void
  19.     {
  20.         // SRID 0 (planar): boundaries and query points are plain long/lat Cartesian, which avoids
  21.         // the EPSG:4326 axis-order pitfall and is exact enough for point-in-polygon country lookup.
  22.         $this->addSql(<<<'SQL'
  23.             CREATE TABLE country_boundaries (
  24.                 id INT UNSIGNED AUTO_INCREMENT NOT NULL,
  25.                 iso_code VARCHAR(2) NOT NULL,
  26.                 geom GEOMETRY NOT NULL SRID 0,
  27.                 PRIMARY KEY(id),
  28.                 INDEX idx_country_boundaries_iso (iso_code),
  29.                 SPATIAL INDEX idx_country_boundaries_geom (geom)
  30.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
  31.         SQL);
  32.     }
  33.     public function down(Schema $schema): void
  34.     {
  35.         $this->addSql('DROP TABLE country_boundaries');
  36.     }
  37. }