Issue316 addresses search by postal code

This commit is contained in:
2021-12-06 12:56:57 +00:00
parent 51bbcab878
commit 938720be52
18 changed files with 805 additions and 23 deletions

View File

@@ -0,0 +1,85 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20211125142016 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('DROP TRIGGER canonicalize_address_reference_on_insert ON chill_main_address_reference');
$this->addSql('DROP TRIGGER canonicalize_address_reference_on_update ON chill_main_address_reference');
$this->addSql('DROP FUNCTION canonicalize_address_reference()');
$this->addSql('ALTER TABLE chill_main_address_reference DROP COLUMN addressCanonical');
}
public function getDescription(): string
{
return 'Add a column "canonicalized" on chill_main_address_reference and add trigger and indexed on it';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_address_reference ADD addressCanonical TEXT DEFAULT \'\' NOT NULL');
$this->addSql('UPDATE chill_main_address_reference
SET addresscanonical =
TRIM(
UNACCENT(
LOWER(
street ||
\' \' ||
streetnumber
)
)
)');
$this->addSql('CREATE OR REPLACE FUNCTION public.canonicalize_address_reference() RETURNS TRIGGER
LANGUAGE plpgsql
AS
$$
BEGIN
NEW.addresscanonical =
TRIM(
UNACCENT(
LOWER(
NEW.street ||
\' \' ||
NEW.streetnumber
)
)
)
;
return NEW;
END
$$');
$this->addSql('CREATE TRIGGER canonicalize_address_reference_on_insert
BEFORE INSERT
ON chill_main_address_reference
FOR EACH ROW
EXECUTE procedure canonicalize_address_reference()');
$this->addSql('CREATE TRIGGER canonicalize_address_reference_on_update
BEFORE UPDATE
ON chill_main_address_reference
FOR EACH ROW
EXECUTE procedure canonicalize_address_reference()');
$this->addSql('CREATE INDEX chill_internal_address_reference_canonicalized ON chill_main_address_reference USING GIST (postcode_id, addressCanonical gist_trgm_ops)');
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20211125142017 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('DROP TRIGGER canonicalize_postal_code_on_insert ON chill_main_postal_code');
$this->addSql('DROP TRIGGER canonicalize_postal_code_on_update ON chill_main_postal_code');
$this->addSql('DROP FUNCTION canonicalize_postal_code()');
$this->addSql('ALTER TABLE chill_main_postal_code DROP COLUMN canonical');
}
public function getDescription(): string
{
return 'Add a column "canonicalized" on postal code';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_postal_code ADD canonical TEXT DEFAULT \'\' NOT NULL');
$this->addSql('UPDATE chill_main_postal_code
SET canonical =
TRIM(
UNACCENT(
LOWER(
code ||
\' \' ||
label
)
)
)');
$this->addSql('CREATE OR REPLACE FUNCTION public.canonicalize_postal_code() RETURNS TRIGGER
LANGUAGE plpgsql
AS
$$
BEGIN
NEW.canonical =
TRIM(
UNACCENT(
LOWER(
NEW.code ||
\' \' ||
NEW.label
)
)
)
;
return NEW;
END
$$');
$this->addSql('CREATE TRIGGER canonicalize_postal_code_on_insert
BEFORE INSERT
ON chill_main_postal_code
FOR EACH ROW
EXECUTE procedure canonicalize_postal_code()');
$this->addSql('CREATE TRIGGER canonicalize_postal_code_on_update
BEFORE UPDATE
ON chill_main_postal_code
FOR EACH ROW
EXECUTE procedure canonicalize_postal_code()');
$this->addSql('CREATE INDEX chill_internal_postal_code_canonicalized ON chill_main_postal_code USING GIST (canonical gist_trgm_ops) WHERE origin = 0');
}
}