fix folder name

This commit is contained in:
2021-03-18 13:37:13 +01:00
parent a2f6773f5a
commit eaa0ad925f
1578 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20141129010948 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql("CREATE SEQUENCE ClosingMotive_id_seq INCREMENT BY 1 MINVALUE 1 START 1;");
$this->addSql("CREATE SEQUENCE person_history_file_id_seq INCREMENT BY 1 MINVALUE 1 START 1;");
$this->addSql("CREATE SEQUENCE Person_id_seq INCREMENT BY 1 MINVALUE 1 START 1;");
$this->addSql("CREATE TABLE ClosingMotive (id INT NOT NULL, name JSON NOT NULL, active BOOLEAN NOT NULL, PRIMARY KEY(id));");
$this->addSql("CREATE TABLE person_history_file (id INT NOT NULL, person_id INT DEFAULT NULL, date_opening DATE NOT NULL, date_closing DATE DEFAULT NULL, memo TEXT NOT NULL, closingMotive_id INT DEFAULT NULL, PRIMARY KEY(id));");
$this->addSql("CREATE INDEX IDX_64A4A621217BBB47 ON person_history_file (person_id);");
$this->addSql("CREATE INDEX IDX_64A4A621504CB38D ON person_history_file (closingMotive_id);");
$this->addSql("CREATE TABLE Person (id INT NOT NULL, nationality_id INT DEFAULT NULL, firstName VARCHAR(255) NOT NULL, lastName VARCHAR(255) NOT NULL, date_of_birth DATE DEFAULT NULL, place_of_birth VARCHAR(255) NOT NULL, genre VARCHAR(9) NOT NULL, memo TEXT NOT NULL, email TEXT NOT NULL, proxyHistoryOpenState BOOLEAN NOT NULL, cFData TEXT NOT NULL, phonenumber TEXT DEFAULT NULL, countryOfBirth_id INT DEFAULT NULL, PRIMARY KEY(id));");
$this->addSql("CREATE INDEX IDX_3370D4403818DA5 ON Person (countryOfBirth_id);");
$this->addSql("CREATE INDEX IDX_3370D4401C9DA55 ON Person (nationality_id);");
$this->addSql("CREATE INDEX person_names ON Person (firstName, lastName);");
$this->addSql("COMMENT ON COLUMN Person.cFData IS '(DC2Type:array)';");
$this->addSql("CREATE TABLE persons_spoken_languages (person_id INT NOT NULL, language_id VARCHAR(255) NOT NULL, PRIMARY KEY(person_id, language_id));");
$this->addSql("CREATE INDEX IDX_7201106F217BBB47 ON persons_spoken_languages (person_id);");
$this->addSql("CREATE INDEX IDX_7201106F82F1BAF4 ON persons_spoken_languages (language_id);");
$this->addSql("ALTER TABLE person_history_file ADD CONSTRAINT FK_64A4A621217BBB47 FOREIGN KEY (person_id) REFERENCES Person (id) NOT DEFERRABLE INITIALLY IMMEDIATE;");
$this->addSql("ALTER TABLE person_history_file ADD CONSTRAINT FK_64A4A621504CB38D FOREIGN KEY (closingMotive_id) REFERENCES ClosingMotive (id) NOT DEFERRABLE INITIALLY IMMEDIATE;");
$this->addSql("ALTER TABLE Person ADD CONSTRAINT FK_3370D4403818DA5 FOREIGN KEY (countryOfBirth_id) REFERENCES Country (id) NOT DEFERRABLE INITIALLY IMMEDIATE;");
$this->addSql("ALTER TABLE Person ADD CONSTRAINT FK_3370D4401C9DA55 FOREIGN KEY (nationality_id) REFERENCES Country (id) NOT DEFERRABLE INITIALLY IMMEDIATE;");
$this->addSql("ALTER TABLE persons_spoken_languages ADD CONSTRAINT FK_7201106F217BBB47 FOREIGN KEY (person_id) REFERENCES Person (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;");
$this->addSql("ALTER TABLE persons_spoken_languages ADD CONSTRAINT FK_7201106F82F1BAF4 FOREIGN KEY (language_id) REFERENCES Language (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;");
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20150212173934 extends AbstractMigration
{
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql("ALTER TABLE person RENAME proxyHistoryOpenState TO proxyAccompanyingPeriodOpenState;");
$this->addSql("ALTER TABLE person_history_file RENAME TO accompanying_period;");
$this->addSql("ALTER SEQUENCE person_history_file_id_seq RENAME TO accompanying_period_id_seq;");
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql("ALTER TABLE accompanying_period RENAME TO person_history_file;");
$this->addSql("ALTER TABLE person RENAME proxyAccompanyingPeriodOpenState TO proxyHistoryOpenState;");
$this->addSql("ALTER SEQUENCE accompanying_period_id_seq RENAME TO person_history_file_id_seq;");
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Chill\MainBundle\Entity\Center;
/**
* Add a center to class person
*/
class Version20150607231010 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add a center on the person entity. The default center is the first '
. 'recorded.';
}
/**
* @param Schema $schema
*/
public function up(Schema $schema): void
{
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.'
);
// retrieve center for setting a default center
$centers = $this->connection->fetchAll('SELECT id FROM centers');
if (count($centers) > 0) {
$defaultCenterId = $centers[0]['id'];
} else { // if no center, performs other checks
//check if there are data in person table
$nbPeople = $this->connection->fetchColumn('SELECT count(*) FROM person');
if ($nbPeople > 0) {
// we have data ! We have to create a center !
$newCenterId = $this->connection->fetchColumn('SELECT nextval(\'centers_id_seq\');');
$this->addSql(
'INSERT INTO centers (id, name) VALUES (:id, :name)',
['id' => $newCenterId, 'name' => 'Auto-created center']
);
$defaultCenterId = $newCenterId;
}
}
$this->addSql('ALTER TABLE person ADD center_id INT');
if (isset($defaultCenterId)) {
$this->addSql('UPDATE person SET center_id = :id', array('id' => $defaultCenterId));
}
$this->addSql('ALTER TABLE person '
. 'ADD CONSTRAINT FK_person_center FOREIGN KEY (center_id) '
. 'REFERENCES centers (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE person ALTER center_id SET NOT NULL');
$this->addSql('CREATE INDEX IDX_person_center ON person (center_id)');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema): void
{
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.'
);
$this->addSql('ALTER TABLE Person DROP CONSTRAINT FK_person_center');
$this->addSql('DROP INDEX IDX_person_center');
$this->addSql('ALTER TABLE Person DROP center_id');
}
}

View File

@@ -0,0 +1,66 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Migration for adapting the Person Bundle to the 'cahier de charge' :
* - RENAMING :
* - - date_of_birth TO birthdate
* - - genre to gender
*
*/
class Version20150811152608 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema): void
{
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE person RENAME COLUMN date_of_birth TO birthdate');
$this->addSql('ALTER TABLE person RENAME COLUMN genre TO gender');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema): void
{
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE person RENAME COLUMN birthdate TO date_of_birth');
$this->addSql('ALTER TABLE person RENAME COLUMN gender TO genre');
}
}

View File

@@ -0,0 +1,63 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Migration for adding maritalstatus to person
*/
class Version20150812110708 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema): void
{
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE TABLE marital_status (
id character varying(10) NOT NULL,
name json NOT NULL,
CONSTRAINT marital_status_pkey PRIMARY KEY (id));');
$this->addSql('ALTER TABLE person ADD COLUMN maritalstatus_id character varying(10)');
$this->addSql('ALTER TABLE person ADD CONSTRAINT fk_person_marital_status FOREIGN KEY (maritalstatus_id) REFERENCES marital_status (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema): void
{
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE person DROP CONSTRAINT fk_person_marital_status;');
$this->addSql('ALTER TABLE person DROP COLUMN maritalstatus_id;');
$this->addSql('DROP TABLE marital_status;');
}
}

View File

@@ -0,0 +1,61 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Migration for adapting the Person Bundle to the 'cahier de charge' :
* - update of accompanyingPerid
*/
class Version20150820113409 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema): void
{
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE accompanying_period RENAME COLUMN date_opening TO openingdate;');
$this->addSql('ALTER TABLE accompanying_period RENAME COLUMN date_closing TO closingdate;');
$this->addSql('ALTER TABLE accompanying_period RENAME COLUMN memo TO remark;');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema): void
{
$this->abortIf(
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE accompanying_period RENAME COLUMN openingdate TO date_opening;');
$this->addSql('ALTER TABLE accompanying_period RENAME COLUMN closingdate TO date_closing;');
$this->addSql('ALTER TABLE accompanying_period RENAME COLUMN remark TO memo;');
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Add a many-to-many relationship between person and addresses
*/
class Version20160310161006 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE TABLE chill_person_persons_to_addresses ('
. 'person_id INT NOT NULL, '
. 'address_id INT NOT NULL, '
. 'PRIMARY KEY(person_id, address_id))');
$this->addSql('CREATE INDEX IDX_4655A196217BBB47 '
. 'ON chill_person_persons_to_addresses (person_id)');
$this->addSql('CREATE INDEX IDX_4655A196F5B7AF75 '
. 'ON chill_person_persons_to_addresses (address_id)');
$this->addSql('ALTER TABLE chill_person_persons_to_addresses '
. 'ADD CONSTRAINT FK_4655A196217BBB47 '
. 'FOREIGN KEY (person_id) '
. 'REFERENCES Person (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_person_persons_to_addresses '
. 'ADD CONSTRAINT FK_4655A196F5B7AF75 '
. 'FOREIGN KEY (address_id) '
. 'REFERENCES chill_main_address (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('DROP TABLE chill_person_persons_to_addresses');
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Check if each person do not have multiple addresses with the same valideFrom
*/
class Version20160422000000 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema): void
{
$stmt = $this->connection->query('SELECT COUNT(*), pe.id, ad.validfrom FROM person AS pe
INNER JOIN chill_person_persons_to_addresses AS pe_ad ON pe.id = pe_ad.person_id
INNER JOIN chill_main_address AS ad ON ad.id = pe_ad.address_id
GROUP BY pe.id, ad.validfrom
HAVING COUNT(*) > 1');
$personWithTwoAddressWithSameValidFrom = $stmt->fetchAll();
foreach ($personWithTwoAddressWithSameValidFrom as $p) {
$this->warnIf(true, 'The person with id '.$p['id'].' has two adresses with the same validFrom date');
}
$this->abortIf(
sizeof($personWithTwoAddressWithSameValidFrom) != 0,
'There exists some person with multiple adress with the same validFrom'
);
}
/**
* @param Schema $schema
*/
public function down(Schema $schema): void
{
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* This migration store the cfdata using the postgresql jsonb type instead
* of the result of the sterialization
*/
class Version20160818113633 extends AbstractMigration
{
/**
* Make a copy of the column cfdata into the column cfdata_old. Then
* remplace the sterialized data into a json data.
*
* @param Schema $schema
*/
public function up(Schema $schema): void
{
$personIdAndCFData = $this->connection->executeQuery('SELECT id, cfdata FROM person');
$this->addSQL('ALTER TABLE person RENAME COLUMN cfdata TO cfdata_old');
$this->addSql('ALTER TABLE person ALTER COLUMN cfdata_old DROP NOT NULL');
$this->addSQL('ALTER TABLE person ADD COLUMN cfdata jsonb');
foreach ($personIdAndCFData as $person) {
$personId = $person['id'];
$cFDataArray = unserialize($person['cfdata']);
$cFDataJson = json_encode($cFDataArray);
$this->addSql(
'UPDATE person set cfdata = :cfdatajson WHERE id = :id',
['cfdatajson' => $cFDataJson, 'id' => $personId]
);
}
}
/**
* Inverse of up
*
* @param Schema $schema
*/
public function down(Schema $schema): void
{
$this->addSQL('ALTER TABLE person DROP COLUMN cfdata');
$this->addSQL('ALTER TABLE person RENAME COLUMN cfdata_old TO cfdata');
$this->addSql('ALTER TABLE person ALTER COLUMN cfdata SET NOT NULL');
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Add the prefix 'chill_person' to all the (db) table name of this bundle
*/
class Version20160818151130 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE person RENAME TO chill_person_person');
$this->addSql('ALTER TABLE person_id_seq RENAME TO chill_person_person_id_seq');
$this->addSql('ALTER TABLE marital_status RENAME TO chill_person_marital_status');
$this->addSql('ALTER TABLE accompanying_period RENAME TO chill_person_accompanying_period');
$this->addSql('ALTER TABLE accompanying_period_id_seq RENAME TO chill_person_accompanying_period_id_seq');
$this->addSql('ALTER TABLE closingmotive RENAME TO chill_person_closingmotive');
$this->addSql('ALTER TABLE closingmotive_id_seq RENAME TO chill_person_closingmotive_id_seq');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema): void
{
$this->addSQL('ALTER TABLE chill_person_person RENAME TO person');
$this->addSql('ALTER TABLE chill_person_person_id_seq RENAME TO person_id_seq');
$this->addSQL('ALTER TABLE chill_person_marital_status RENAME TO marital_status ');
$this->addSQl('ALTER TABLE chill_person_accompanying_period RENAME TO accompanying_period');
$this->addSql('ALTER TABLE chill_person_accompanying_period_id_seq RENAME TO accompanying_period_id_seq');
$this->addSQL('ALTER TABLE chill_person_closingmotive RENAME TO closingmotive');
$this->addSql('ALTER TABLE chill_person_closingmotive_id_seq RENAME TO closingmotive_id_seq');
}
}

View File

@@ -0,0 +1,123 @@
<?php
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Add postgresql functions to compute last address on person.
*/
class Version20170117131924 extends AbstractMigration
{
public $fields = array(
'address_id' => 'integer',
'streetaddress1' => 'varchar(255)',
'streetaddress2' => 'varchar(255)',
'validfrom' => 'date',
'postcode_label' => 'varchar(255)',
'postcode_code' => 'varchar(100)',
'postcode_id' => 'integer',
'country_name' => 'json',
'country_code' => 'varchar(3)',
'country_id' => 'integer'
);
/**
* @param Schema $schema
*/
public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
CREATE OR REPLACE FUNCTION public.get_last_address (
pid integer,
before_date date)
RETURNS TABLE(
person_id integer,
address_id integer,
streetaddress1 varchar(255),
streetaddress2 varchar(255),
validfrom date,
postcode_label varchar(255),
postcode_code varchar(100),
postcode_id integer,
country_name json,
country_code varchar(3),
country_id integer)
AS
$BODY$
SELECT
pid AS person_id,
chill_main_address.id AS address_id,
chill_main_address.streetaddress1,
chill_main_address.streetaddress2,
chill_main_address.validfrom,
chill_main_postal_code.label,
chill_main_postal_code.code,
chill_main_postal_code.id AS postal_code_id,
country.name,
country.countrycode,
country.id AS country_id
FROM chill_main_address
JOIN (
SELECT
chill_main_address.id AS address_id,
validfrom,
rank() OVER (PARTITION BY person_id ORDER BY validfrom DESC) as pos
FROM chill_person_persons_to_addresses
JOIN chill_main_address ON chill_person_persons_to_addresses.address_id = chill_main_address.id
WHERE person_id = pid
AND chill_main_address.validfrom <= before_date
) AS ranking ON ranking.address_id = chill_main_address.id
JOIN chill_main_postal_code ON chill_main_address.postcode_id = chill_main_postal_code.id
JOIN country ON chill_main_postal_code.country_id = country.id
WHERE ranking.pos = 1
$BODY$
LANGUAGE sql VOLATILE
COST 100;
SQL
);
// create function to get part of address
foreach ($this->fields as $var => $type) {
$this->addSql(sprintf(<<<'SQL'
CREATE OR REPLACE FUNCTION get_last_address_%s (
pid integer,
before_date date)
RETURNS %s AS
$BODY$
SELECT %s FROM get_last_address(pid, before_date)
$BODY$
LANGUAGE sql volatile
COST 100;
SQL
, $var, $type, $var));
}
}
/**
* @param Schema $schema
*/
public function down(Schema $schema): void
{
// drop function to get parts of address
foreach ($this->fields as $var => $type) {
$this->addSql(<<<SQL
DROP FUNCTION get_last_address_$var (
pid integer,
before_date date)
SQL
);
}
$this->addSQL(<<<SQL
DROP FUNCTION public.get_last_address (
pid integer,
before_date date)
SQL
);
}
}

View File

@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Add a contactInfo and a mobilenumber columns on person. Change the email column.
*/
final class Version20180518144221 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_person_person ADD contactInfo TEXT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_person ADD mobilenumber TEXT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_person ALTER email DROP NOT NULL');
}
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_person_person DROP contactInfo');
$this->addSql('ALTER TABLE chill_person_person DROP mobilenumber');
$this->addSql('ALTER TABLE chill_person_person ALTER email SET NOT NULL');
}
}

View File

@@ -0,0 +1,31 @@
<?php declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Correction: copie les infos de email vers contactInfo.
*
* Previously, data from contact where stored in 'email' column
*/
final class Version20180820120000 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('UPDATE chill_person_person SET contactInfo=email');
$this->addSql('UPDATE chill_person_person SET email=\'\'');
}
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('UPDATE chill_person_person SET email=contactInfo');
$this->addSql('UPDATE chill_person_person SET contactInfo=\'\'');
}
}

View File

@@ -0,0 +1,26 @@
<?php declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Set person gender not null
*/
final class Version20181005140249 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_person_person ALTER gender DROP NOT NULL');
}
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_person_person ALTER gender SET NOT NULL');
}
}

View File

@@ -0,0 +1,79 @@
<?php declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add fullnameCanonical column for trigram matching (fast searching)
*/
final class Version20181023101621 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql("ALTER TABLE chill_person_person ADD fullnameCanonical VARCHAR(255) DEFAULT '' ");
$this->addSql("UPDATE chill_person_person SET fullnameCanonical=LOWER(UNACCENT(CONCAT(firstname, ' ', lastname)))");
$this->addSql("CREATE INDEX fullnameCanonical_trgm_idx ON chill_person_person USING GIN (fullnameCanonical gin_trgm_ops)");
$this->addSql(<<<'SQL'
CREATE OR REPLACE FUNCTION canonicalize_fullname_on_update() RETURNS TRIGGER AS
$BODY$
BEGIN
IF NEW.firstname <> OLD.firstname OR NEW.lastname <> OLD.lastname
THEN
UPDATE chill_person_person
SET fullnameCanonical=LOWER(UNACCENT(CONCAT(NEW.firstname, ' ', NEW.lastname)))
WHERE id=NEW.id;
END IF;
RETURN NEW;
END;
$BODY$ LANGUAGE PLPGSQL;
SQL
);
$this->addSql(<<<SQL
CREATE TRIGGER canonicalize_fullname_on_update
AFTER UPDATE
ON chill_person_person
FOR EACH ROW
WHEN (pg_trigger_depth() = 0)
EXECUTE PROCEDURE canonicalize_fullname_on_update();
SQL
);
$this->addSql(<<<'SQL'
CREATE OR REPLACE FUNCTION canonicalize_fullname_on_insert() RETURNS TRIGGER AS
$BODY$
BEGIN
UPDATE chill_person_person
SET fullnameCanonical=LOWER(UNACCENT(CONCAT(NEW.firstname, ' ', NEW.lastname)))
WHERE id=NEW.id;
RETURN NEW;
END;
$BODY$ LANGUAGE PLPGSQL;
SQL
);
$this->addSql(<<<SQL
CREATE TRIGGER canonicalize_fullname_on_insert
AFTER INSERT
ON chill_person_person
FOR EACH ROW
EXECUTE PROCEDURE canonicalize_fullname_on_insert();
SQL
);
}
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('DROP INDEX fullnameCanonical_trgm_idx');
$this->addSql('ALTER TABLE chill_person_person DROP fullnameCanonical');
$this->addSql('DROP TRIGGER canonicalize_fullname_on_update ON chill_person_person');
$this->addSql('DROP FUNCTION canonicalize_fullname_on_update()');
$this->addSql('DROP TRIGGER canonicalize_fullname_on_insert ON chill_person_person');
$this->addSql('DROP FUNCTION canonicalize_fullname_on_insert()');
}
}

View File

@@ -0,0 +1,24 @@
<?php declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add a link between accompanying periods and users
*/
final class Version20190701124238 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_accompanying_period ADD user_id INT DEFAULT NULL;');
$this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A868A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE;');
$this->addSql('CREATE INDEX IDX_E260A868A76ED395 ON chill_person_accompanying_period (user_id);');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_accompanying_period DROP user_id');
}
}

View File

@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add an index for phonenumber and mobile number
*/
final class Version20191106103452 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql("CREATE INDEX phonenumber_trgm_idx
ON public.chill_person_person USING gin
(phonenumber gin_trgm_ops)");
$this->addSql("CREATE INDEX mobilenumber_trgm_idx
ON public.chill_person_person USING gin
(mobilenumber gin_trgm_ops)");
}
public function down(Schema $schema): void
{
$this->addSql("DROP INDEX phonenumber_trgm_idx");
$this->addSql("DROP INDEX mobilenumber_trgm_idx");
}
}

View File

@@ -0,0 +1,31 @@
<?php declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add person alt name table
*/
final class Version20200128084445 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql("CREATE SEQUENCE chill_person_alt_name_id_seq INCREMENT BY 1 MINVALUE 1 START 1");
$this->addSql("CREATE TABLE chill_person_alt_name (id INT NOT NULL, person_id INT DEFAULT NULL, key VARCHAR(255) NOT NULL, label TEXT NOT NULL, PRIMARY KEY(id))");
$this->addSql("CREATE INDEX IDX_2628668E217BBB47 ON chill_person_alt_name (person_id)");
$this->addSql("ALTER TABLE chill_person_alt_name ADD CONSTRAINT FK_2628668E217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE");
}
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql("DROP INDEX IDX_2628668E217BBB47");
$this->addSql("DROP TABLE chill_person_alt_name");
$this->addSql("DROP SEQUENCE chill_person_alt_name_id_seq");
}
}

View File

@@ -0,0 +1,154 @@
<?php declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add triggers for canicalizing alt names
*/
final class Version20200130213446 extends AbstractMigration
{
const CANONICALIZE_FULLNAME_ON_UPDATE = <<<'SQL'
CREATE OR REPLACE FUNCTION public.canonicalize_fullname_on_update()
RETURNS trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$
DECLARE
cur_alt_names CURSOR(pid INTEGER) FOR SELECT label FROM chill_person_alt_name WHERE person_id = pid;
alt_name RECORD;
fullname_canonicalized TEXT;
BEGIN
fullname_canonicalized := LOWER(UNACCENT(CONCAT(NEW.firstname, ' ', NEW.lastname)));
OPEN cur_alt_names(pid:=NEW.id);
LOOP
FETCH cur_alt_names INTO alt_name;
EXIT WHEN NOT FOUND;
fullname_canonicalized := CONCAT(fullname_canonicalized, ' ',
LOWER(UNACCENT(alt_name.label)));
END LOOP;
CLOSE cur_alt_names;
IF fullname_canonicalized <> OLD.fullnameCanonical
THEN
UPDATE chill_person_person
SET fullnameCanonical=fullname_canonicalized
WHERE id=NEW.id;
END IF;
RETURN NEW;
END;
$BODY$;
SQL;
const CANONICALIZE_FULLNAME_ON_ALT_NAME_ALTER = <<<'SQL'
CREATE OR REPLACE FUNCTION public.canonicalize_fullname_on_alt_name_alter()
RETURNS trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$
DECLARE
target_person_id INTEGER;
cur_person CURSOR(pid INTEGER) FOR SELECT firstname, lastname FROM chill_person_person WHERE id = pid;
person RECORD;
cur_alt_names CURSOR(pid INTEGER) FOR SELECT label FROM chill_person_alt_name WHERE person_id = pid;
alt_name RECORD;
fullname_canonicalized TEXT;
BEGIN
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE'
THEN target_person_id := NEW.person_id;
ELSE target_person_id := OLD.person_id;
END IF;
OPEN cur_person(pid:=target_person_id);
FETCH cur_person INTO person;
fullname_canonicalized := LOWER(UNACCENT(CONCAT(person.firstname, ' ', person.lastname)));
-- loop over alt names
OPEN cur_alt_names(pid:=target_person_id);
LOOP
FETCH cur_alt_names INTO alt_name;
EXIT WHEN NOT FOUND;
fullname_canonicalized := CONCAT(fullname_canonicalized, ' ',
LOWER(UNACCENT(alt_name.label)));
END LOOP;
CLOSE cur_alt_names;
CLOSE cur_person;
UPDATE chill_person_person
SET fullnameCanonical=fullname_canonicalized
WHERE id=target_person_id;
RETURN NEW;
END;
$BODY$;
SQL;
const CANONICALIZE_FULLNAME_ON_ALT_NAME_INSERT = <<<SQL
CREATE TRIGGER canonicalize_fullname_on_alt_name_insert
AFTER INSERT
ON chill_person_alt_name
FOR EACH ROW
EXECUTE PROCEDURE canonicalize_fullname_on_alt_name_alter();
SQL;
const CANONICALIZE_FULLNAME_ON_ALT_NAME_DELETE = <<<SQL
CREATE TRIGGER canonicalize_fullname_on_alt_name_delete
AFTER DELETE
ON chill_person_alt_name
FOR EACH ROW
EXECUTE PROCEDURE canonicalize_fullname_on_alt_name_alter();
SQL;
const CANONICALIZE_FULLNAME_ON_ALT_NAME_UPDATE = <<<SQL
CREATE TRIGGER canonicalize_fullname_on_alt_name_update
AFTER UPDATE
ON chill_person_alt_name
FOR EACH ROW
EXECUTE PROCEDURE canonicalize_fullname_on_alt_name_alter();
SQL;
public function up(Schema $schema): void
{
// update fullname
$this->addSql("ALTER TABLE chill_person_person ALTER fullnamecanonical TYPE TEXT;");
$this->addSql("ALTER TABLE chill_person_person ALTER fullnamecanonical DROP DEFAULT;");
// insert function and triggers
$this->addSql(self::CANONICALIZE_FULLNAME_ON_UPDATE);
$this->addSql(self::CANONICALIZE_FULLNAME_ON_ALT_NAME_ALTER);
$this->addSql(self::CANONICALIZE_FULLNAME_ON_ALT_NAME_INSERT);
$this->addSql(self::CANONICALIZE_FULLNAME_ON_ALT_NAME_DELETE);
$this->addSql(self::CANONICALIZE_FULLNAME_ON_ALT_NAME_UPDATE);
}
public function down(Schema $schema): void
{
$this->addSql("DROP TRIGGER canonicalize_fullname_on_alt_name_update ON chill_person_alt_name;");
$this->addSql("DROP TRIGGER canonicalize_fullname_on_alt_name_insert ON chill_person_alt_name;");
$this->addSql("DROP TRIGGER canonicalize_fullname_on_alt_name_delete ON chill_person_alt_name;");
$this->addSql("DROP FUNCTION canonicalize_fullname_on_alt_name_alter();");
$this->addSql(<<<'SQL'
CREATE OR REPLACE FUNCTION canonicalize_fullname_on_update() RETURNS TRIGGER AS
$BODY$
BEGIN
IF NEW.firstname <> OLD.firstname OR NEW.lastname <> OLD.lastname
THEN
UPDATE chill_person_person
SET fullnameCanonical=LOWER(UNACCENT(CONCAT(NEW.firstname, ' ', NEW.lastname)))
WHERE id=NEW.id;
END IF;
RETURN NEW;
END;
$BODY$ LANGUAGE PLPGSQL;
SQL
);
}
}

View File

@@ -0,0 +1,31 @@
<?php declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add a relationship parent/child inside closing motives
*/
final class Version20200310090632 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_person_closingmotive ADD parent_id INT DEFAULT NULL');
$this->addSql('COMMENT ON COLUMN chill_person_closingmotive.name IS \'(DC2Type:json_array)\'');
$this->addSql('ALTER TABLE chill_person_closingmotive ADD CONSTRAINT FK_92351ECE727ACA70 FOREIGN KEY (parent_id) REFERENCES chill_person_closingmotive (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_92351ECE727ACA70 ON chill_person_closingmotive (parent_id)');
$this->addsql("ALTER TABLE chill_person_closingmotive ADD ordering DOUBLE PRECISION DEFAULT '0' NOT NULL;");
}
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_person_closingmotive DROP parent_id');
$this->addSql('ALTER TABLE chill_person_closingmotive DROP ordering');
}
}

View File

@@ -0,0 +1,138 @@
<?php declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200422125935 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql('DROP FUNCTION get_last_address(integer, date)');
$this->addSql(<<<'SQL'
CREATE OR REPLACE FUNCTION public.get_last_address (
pid integer,
before_date date)
RETURNS TABLE(
person_id integer,
address_id integer,
streetaddress1 varchar(255),
streetaddress2 varchar(255),
validfrom date,
postcode_label varchar(255),
postcode_code varchar(100),
postcode_id integer,
isnoaddress boolean,
country_name json,
country_code varchar(3),
country_id integer)
AS
$BODY$
SELECT
pid AS person_id,
chill_main_address.id AS address_id,
chill_main_address.streetaddress1,
chill_main_address.streetaddress2,
chill_main_address.validfrom,
chill_main_postal_code.label,
chill_main_postal_code.code,
chill_main_postal_code.id AS postal_code_id,
chill_main_address.isnoaddress AS isnoaddress,
country.name,
country.countrycode,
country.id AS country_id
FROM chill_main_address
JOIN (
SELECT
chill_main_address.id AS address_id,
validfrom,
rank() OVER (PARTITION BY person_id ORDER BY validfrom DESC) as pos
FROM chill_person_persons_to_addresses
JOIN chill_main_address ON chill_person_persons_to_addresses.address_id = chill_main_address.id
WHERE person_id = pid
AND chill_main_address.validfrom <= before_date
) AS ranking ON ranking.address_id = chill_main_address.id
JOIN chill_main_postal_code ON chill_main_address.postcode_id = chill_main_postal_code.id
JOIN country ON chill_main_postal_code.country_id = country.id
WHERE ranking.pos = 1
$BODY$
LANGUAGE sql VOLATILE
COST 100;
SQL
);
$this->addSql(<<<'SQL'
CREATE OR REPLACE FUNCTION get_last_address_isnoaddress (
pid integer,
before_date date)
RETURNS BOOL AS
$BODY$
SELECT isnoaddress FROM get_last_address(pid, before_date)
$BODY$
LANGUAGE sql volatile
COST 100;
SQL
);
}
public function down(Schema $schema): void
{
$this->addSql('DROP FUNCTION public.get_last_address_isnoaddress(integer, date);');
$this->addSql('DROP FUNCTION get_last_address(integer, date)');
$this->addSql(<<<'SQL'
CREATE OR REPLACE FUNCTION public.get_last_address (
pid integer,
before_date date)
RETURNS TABLE(
person_id integer,
address_id integer,
streetaddress1 varchar(255),
streetaddress2 varchar(255),
validfrom date,
postcode_label varchar(255),
postcode_code varchar(100),
postcode_id integer,
country_name json,
country_code varchar(3),
country_id integer)
AS
$BODY$
SELECT
pid AS person_id,
chill_main_address.id AS address_id,
chill_main_address.streetaddress1,
chill_main_address.streetaddress2,
chill_main_address.validfrom,
chill_main_postal_code.label,
chill_main_postal_code.code,
chill_main_postal_code.id AS postal_code_id,
country.name,
country.countrycode,
country.id AS country_id
FROM chill_main_address
JOIN (
SELECT
chill_main_address.id AS address_id,
validfrom,
rank() OVER (PARTITION BY person_id ORDER BY validfrom DESC) as pos
FROM chill_person_persons_to_addresses
JOIN chill_main_address ON chill_person_persons_to_addresses.address_id = chill_main_address.id
WHERE person_id = pid
AND chill_main_address.validfrom <= before_date
) AS ranking ON ranking.address_id = chill_main_address.id
JOIN chill_main_postal_code ON chill_main_address.postcode_id = chill_main_postal_code.id
JOIN country ON chill_main_postal_code.country_id = country.id
WHERE ranking.pos = 1
$BODY$
LANGUAGE sql VOLATILE
COST 100;
SQL
);
}
}