Merge branch 'master' into household_filiation

This commit is contained in:
2021-11-12 17:20:46 +01:00
298 changed files with 8036 additions and 3185 deletions

View File

@@ -17,7 +17,6 @@ class Version20150607231010 extends AbstractMigration
. 'recorded.';
}
/**
* @param Schema $schema
*/
@@ -28,36 +27,26 @@ class Version20150607231010 extends AbstractMigration
'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');
// retrieve center for setting a default center
$stmt = $this->connection->executeQuery("SELECT id FROM centers ORDER BY id ASC LIMIT 1");
$center = $stmt->fetchOne();
if ($center !== false) {
$defaultCenterId = $center['id'];
}
if (isset($defaultCenterId)) {
$this->addSql('UPDATE person SET center_id = :id', array('id' => $defaultCenterId));
}
// this will fail if a person is defined, which should not happen any more at this
// time of writing (2021-11-09)
$this->addSql('ALTER TABLE person ALTER center_id SET NOT NULL');
$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)');
}

View File

@@ -15,7 +15,6 @@ final class Version20200310090632 extends AbstractMigration
$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;");

View File

@@ -24,6 +24,5 @@ final class Version20210419112619 extends AbstractMigration
public function down(Schema $schema) : void
{
$this->addSql('COMMENT ON COLUMN chill_person_accompanying_period_closingmotive.name IS \'(DC2Type:json_array)\'');
}
}

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Validation added to accompanying period resources and accompanying period.
*/
final class Version20211020131133 extends AbstractMigration
{
public function getDescription(): string
{
return 'Validation added to accompanying period resources and accompanying period.';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE UNIQUE INDEX person_unique ON chill_person_accompanying_period_resource (person_id, accompanyingperiod_id) WHERE person_id IS NOT NULL');
$this->addSql('CREATE UNIQUE INDEX thirdparty_unique ON chill_person_accompanying_period_resource (thirdparty_id, accompanyingperiod_id) WHERE thirdparty_id IS NOT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX person_unique');
$this->addSql('DROP INDEX thirdparty_unique');
}
}

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Custom constraint added to database to prevent identical participations.
*/
final class Version20211021125359 extends AbstractMigration
{
public function getDescription(): string
{
return 'Custom constraint added to database to prevent identical participations.';
}
public function up(Schema $schema): void
{
// creates a constraint 'participations may not overlap'
$this->addSql('ALTER TABLE chill_person_accompanying_period_participation ADD CONSTRAINT '.
"participations_no_overlap EXCLUDE USING GIST(
-- extension btree_gist required to include comparaison with integer
person_id WITH =, accompanyingperiod_id WITH =,
daterange(startdate, enddate) WITH &&
)
INITIALLY DEFERRED");
}
public function down(Schema $schema): void
{
$this->addSql('CREATE UNIQUE INDEX participation_unique ON chill_person_accompanying_period_participation (accompanyingperiod_id, person_id)');
}
}

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add Civility to Person
*/
final class Version20211108100849 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add Civility to Person';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_person ADD civility_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_person ADD CONSTRAINT FK_BF210A1423D6A298 FOREIGN KEY (civility_id) REFERENCES chill_main_civility (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_BF210A1423D6A298 ON chill_person_person (civility_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_person DROP CONSTRAINT FK_BF210A1423D6A298');
$this->addSql('DROP INDEX IDX_BF210A1423D6A298');
$this->addSql('ALTER TABLE chill_person_person DROP civility_id');
}
}