feat: Affectation des enseignants aux classes et matières

Permet aux administrateurs d'associer un enseignant à une classe pour une
matière donnée au sein d'une année scolaire. Cette brique est nécessaire
pour construire les emplois du temps et les carnets de notes par la suite.

Le modèle impose l'unicité du triplet enseignant × classe × matière par
année scolaire, avec réactivation automatique d'une affectation retirée
plutôt que duplication. L'isolation multi-tenant est garantie au niveau
du repository (findById/get filtrent par tenant_id).
This commit is contained in:
2026-02-13 20:22:39 +01:00
parent 73a473ec93
commit 88e7f319db
61 changed files with 6484 additions and 52 deletions

View File

@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Adds tenant_id to the UNIQUE constraint on teacher_assignments.
*
* The original constraint (teacher_id, school_class_id, subject_id, academic_year_id)
* allowed the same tuple to exist across different tenants, which is correct,
* but did not scope uniqueness per tenant. Including tenant_id ensures that
* uniqueness is enforced within each tenant boundary.
*/
final class Version20260212200000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add tenant_id to teacher_assignments UNIQUE constraint for multi-tenant safety';
}
public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
ALTER TABLE teacher_assignments
DROP CONSTRAINT IF EXISTS teacher_assignments_teacher_id_school_class_id_subject_id_acad_key
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE teacher_assignments
ADD CONSTRAINT teacher_assignments_tenant_teacher_class_subject_year_key
UNIQUE (tenant_id, teacher_id, school_class_id, subject_id, academic_year_id)
SQL);
}
public function down(Schema $schema): void
{
$this->addSql(<<<'SQL'
ALTER TABLE teacher_assignments
DROP CONSTRAINT IF EXISTS teacher_assignments_tenant_teacher_class_subject_year_key
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE teacher_assignments
ADD CONSTRAINT teacher_assignments_teacher_id_school_class_id_subject_id_acad_key
UNIQUE (teacher_id, school_class_id, subject_id, academic_year_id)
SQL);
}
}