migrations/Version20220511122600.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.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20220511122600 extends AbstractMigration
  10. {
  11.     public function getDescription() : string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema) : void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  19.         $this->addSql("SET GLOBAL log_bin_trust_function_creators = 1;");
  20.         $this->addSql("CREATE DEFINER=`root`@`localhost` " .
  21.             "FUNCTION `get_distance_kilometres`(`lat1` DOUBLE, `lng1` DOUBLE, `lat2` DOUBLE, `lng2` DOUBLE) " .
  22.             "RETURNS DOUBLE NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER " .
  23.             "BEGIN " .
  24.             "    DECLARE rlo1 DOUBLE; " .
  25.             "    DECLARE rla1 DOUBLE; " .
  26.             "    DECLARE rlo2 DOUBLE; " .
  27.             "    DECLARE rla2 DOUBLE; " .
  28.             "    DECLARE dlo DOUBLE; " .
  29.             "    DECLARE dla DOUBLE; " .
  30.             "    DECLARE a DOUBLE; " .
  31.             "    SET rlo1 = RADIANS(lng1); " .
  32.             "    SET rla1 = RADIANS(lat1); " .
  33.             "    SET rlo2 = RADIANS(lng2); " .
  34.             "    SET rla2 = RADIANS(lat2); " .
  35.             "    SET dlo = (rlo2 - rlo1) / 2; " .
  36.             "    SET dla = (rla2 - rla1) / 2; " .
  37.             "    SET a = SIN(dla) * SIN(dla) + COS(rla1) * COS(rla2) * SIN(dlo) * SIN(dlo); " .
  38.             "    RETURN round( (6378137 * 2 * ATAN2(SQRT(a), SQRT(1 - a))/1000),2); " .
  39.             "END ");
  40.     }
  41.     public function down(Schema $schema) : void
  42.     {
  43.         // this down() migration is auto-generated, please modify it to your needs
  44.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  45.         $this->addSql('DROP FUNCTION IF EXISTS `get_distance_kilometres`');
  46.     }
  47. }