feat : ajout du nouveau système de contrat et ajout de filtre d'impression
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
This commit is contained in:
33
migrations/Version20260226203000.php
Normal file
33
migrations/Version20260226203000.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260226203000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add contract nature to employee contract periods';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql("ALTER TABLE employee_contract_periods ADD contract_nature VARCHAR(20) DEFAULT 'CDI' NOT NULL");
|
||||
$this->addSql("
|
||||
UPDATE employee_contract_periods p
|
||||
SET contract_nature = 'INTERIM'
|
||||
FROM contracts c
|
||||
WHERE p.contract_id = c.id
|
||||
AND LOWER(c.name) LIKE '%interim%'
|
||||
");
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE employee_contract_periods DROP contract_nature');
|
||||
}
|
||||
}
|
||||
82
migrations/Version20260226210000.php
Normal file
82
migrations/Version20260226210000.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\Migrations\Exception\IrreversibleMigration;
|
||||
|
||||
final class Version20260226210000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Reassign legacy INTERIM contract to a TIME 35h contract and remove legacy INTERIM contract row';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql(
|
||||
<<<'SQL'
|
||||
DO $$
|
||||
DECLARE
|
||||
legacy_interim_contract_id INT;
|
||||
target_time_35h_contract_id INT;
|
||||
BEGIN
|
||||
-- Contrat legacy "Intérim" (ancien modèle).
|
||||
SELECT c.id
|
||||
INTO legacy_interim_contract_id
|
||||
FROM contracts c
|
||||
WHERE LOWER(c.name) LIKE '%interim%'
|
||||
ORDER BY c.id
|
||||
LIMIT 1;
|
||||
|
||||
-- Si déjà supprimé, on ne fait rien.
|
||||
IF legacy_interim_contract_id IS NULL THEN
|
||||
RETURN;
|
||||
END IF;
|
||||
|
||||
-- Contrat cible: suivi horaire 35h.
|
||||
SELECT c.id
|
||||
INTO target_time_35h_contract_id
|
||||
FROM contracts c
|
||||
WHERE c.tracking_mode = 'TIME'
|
||||
AND c.weekly_hours = 35
|
||||
AND c.id <> legacy_interim_contract_id
|
||||
ORDER BY
|
||||
CASE WHEN LOWER(c.name) = '35h' THEN 0 ELSE 1 END,
|
||||
c.id
|
||||
LIMIT 1;
|
||||
|
||||
IF target_time_35h_contract_id IS NULL THEN
|
||||
RAISE EXCEPTION 'No TIME 35h contract found to replace legacy INTERIM contract id=%', legacy_interim_contract_id;
|
||||
END IF;
|
||||
|
||||
-- Ré-assigne l'historique de périodes.
|
||||
UPDATE employee_contract_periods
|
||||
SET contract_id = target_time_35h_contract_id
|
||||
WHERE contract_id = legacy_interim_contract_id;
|
||||
|
||||
-- Ré-assigne le pointeur actuel employé (compat legacy / affichage).
|
||||
UPDATE employees
|
||||
SET contract_id = target_time_35h_contract_id
|
||||
WHERE contract_id = legacy_interim_contract_id;
|
||||
|
||||
-- Garde-fou FK avant suppression.
|
||||
IF EXISTS (SELECT 1 FROM employee_contract_periods p WHERE p.contract_id = legacy_interim_contract_id)
|
||||
OR EXISTS (SELECT 1 FROM employees e WHERE e.contract_id = legacy_interim_contract_id) THEN
|
||||
RAISE EXCEPTION 'Legacy INTERIM contract id=% is still referenced', legacy_interim_contract_id;
|
||||
END IF;
|
||||
|
||||
DELETE FROM contracts WHERE id = legacy_interim_contract_id;
|
||||
END $$;
|
||||
SQL
|
||||
);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
throw new IrreversibleMigration('This migration performs data reassignment and contract deletion.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user