mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
create view for current address and apply on Person/Household normalizer
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Person;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Create a view for assembling household, person and addresses
|
||||
*/
|
||||
final class Version20210616102900 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Create a view for assembling household, person and addresses';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql("CREATE VIEW view_chill_person_household_address AS ".
|
||||
"SELECT ".
|
||||
"members.person_id AS person_id, ".
|
||||
"members.household_id AS household_id, ".
|
||||
"members.id AS member_id, ".
|
||||
"address.id AS address_id, ".
|
||||
"CASE WHEN address.validFrom < members.startDate THEN members.startDate ELSE address.validFrom END AS validFrom, ".
|
||||
"CASE WHEN COALESCE(address.validTo, 'infinity') < COALESCE(members.endDate, 'infinity') THEN address.validTo ELSE members.endDate END AS validTo ".
|
||||
"FROM chill_person_household_members AS members ".
|
||||
"JOIN chill_person_household_to_addresses AS household_to_addr ON household_to_addr.household_id = members.household_id ".
|
||||
"JOIN chill_main_address AS address ON household_to_addr.address_id = address.id ".
|
||||
"AND daterange(address.validFrom, address.validTo) && daterange(members.startDate, members.endDate) ".
|
||||
"WHERE members.sharedhousehold IS TRUE "
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql("DROP VIEW view_chill_person_household_address");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user