mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-30 14:06:13 +00:00
Fix export for people created before 'createdAt' column introduction
This commit introduces a migration to fix the export for individuals who were created before the introduction of the 'createdAt' column. The 'startdate' column is now updated to match the individual's first activity date. This migration is irreversible. It's been added as a response to Issue #228
This commit is contained in:
parent
dab80a84d8
commit
f7184ca7bb
6
.changes/unreleased/Fixed-20231207-232129.yaml
Normal file
6
.changes/unreleased/Fixed-20231207-232129.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
kind: Fixed
|
||||
body: Fix export of activity for people created before the introduction of the createdAt
|
||||
column on person (during v1)
|
||||
time: 2023-12-07T23:21:29.976822313+01:00
|
||||
custom:
|
||||
Issue: "228"
|
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace Chill\Migrations\Person;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Fix lines in chill_person_person_center_history for people created before the introduction of the createdAt column.
|
||||
*
|
||||
* This class represents a migration for fixing lines in the 'chill_person_person_center_history' table.
|
||||
*
|
||||
* It updates the 'startdate' column for people created before the introduction
|
||||
* of the 'createdAt' column, and set it at the first activity date. This migration is irreversible.
|
||||
*/
|
||||
final class Version20231207221700 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Fix lines in chill_person_person_center_history for people created before the introduction of the createdAt column';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('WITH first_history_line AS (SELECT *
|
||||
FROM (SELECT id,
|
||||
person_id,
|
||||
startdate,
|
||||
rank() OVER (PARTITION BY person_id ORDER BY startdate ASC, id ASC) AS r
|
||||
FROM chill_person_person_center_history) AS sk
|
||||
WHERE sk.r = 1),
|
||||
first_activity AS (SELECT *
|
||||
FROM (SELECT id, date, person_id, rank() OVER (PARTITION BY person_id ORDER BY date ASC, id ASC) AS r
|
||||
FROM activity
|
||||
WHERE person_id IS NOT NULL) sq
|
||||
WHERE sq.r = 1)
|
||||
UPDATE chill_person_person_center_history cppch SET startdate=first_activity.date
|
||||
FROM first_history_line, first_activity
|
||||
WHERE
|
||||
first_history_line.id = cppch.id
|
||||
AND first_activity.person_id = cppch.person_id
|
||||
AND first_activity.date < first_history_line.startDate');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->throwIrreversibleMigrationException();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user