feat: Liaison parents-enfants avec gestion des tuteurs
Les parents doivent pouvoir suivre la scolarité de leurs enfants (notes, emploi du temps, devoirs). Cela nécessite un lien formalisé entre le compte parent et le compte élève, géré par les administrateurs. Le lien est établi soit manuellement via l'interface d'administration, soit automatiquement lors de l'activation du compte parent lorsque l'invitation inclut un élève cible. Ce lien conditionne l'accès aux données scolaires de l'enfant (autorisations vérifiées par un voter dédié).
This commit is contained in:
48
backend/migrations/Version20260210100000.php
Normal file
48
backend/migrations/Version20260210100000.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Creates the student_guardians table for parent-child linking.
|
||||
*
|
||||
* Each student can have at most 2 guardians (parents/tutors).
|
||||
* The constraint is enforced at application level (see StudentGuardian::MAX_GUARDIANS_PER_STUDENT).
|
||||
* The UNIQUE constraint on (student_id, guardian_id) prevents duplicate links.
|
||||
*/
|
||||
final class Version20260210100000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Create student_guardians table for parent-child linking (Story 2.7)';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE IF NOT EXISTS student_guardians (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
student_id UUID NOT NULL,
|
||||
guardian_id UUID NOT NULL,
|
||||
relationship_type VARCHAR(50) NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
created_by UUID,
|
||||
tenant_id UUID NOT NULL,
|
||||
UNIQUE(student_id, guardian_id)
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql('CREATE INDEX IF NOT EXISTS idx_student_guardians_tenant ON student_guardians(tenant_id)');
|
||||
$this->addSql('CREATE INDEX IF NOT EXISTS idx_student_guardians_guardian ON student_guardians(guardian_id)');
|
||||
$this->addSql('CREATE INDEX IF NOT EXISTS idx_student_guardians_student ON student_guardians(student_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP TABLE IF EXISTS student_guardians');
|
||||
}
|
||||
}
|
||||
43
backend/migrations/Version20260210120000.php
Normal file
43
backend/migrations/Version20260210120000.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Makes the unique constraint on student_guardians tenant-scoped.
|
||||
*
|
||||
* The original UNIQUE(student_id, guardian_id) prevented the same pair across all tenants.
|
||||
* Since UUIDs are globally unique this was not a real issue, but adding tenant_id
|
||||
* to the constraint follows defense-in-depth for multi-tenant isolation.
|
||||
*/
|
||||
final class Version20260210120000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add tenant_id to student_guardians unique constraint for multi-tenant safety';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE student_guardians DROP CONSTRAINT IF EXISTS student_guardians_student_id_guardian_id_key');
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE student_guardians
|
||||
ADD CONSTRAINT student_guardians_student_guardian_tenant_unique
|
||||
UNIQUE (student_id, guardian_id, tenant_id)
|
||||
SQL);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE student_guardians DROP CONSTRAINT IF EXISTS student_guardians_student_guardian_tenant_unique');
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE student_guardians
|
||||
ADD CONSTRAINT student_guardians_student_id_guardian_id_key
|
||||
UNIQUE (student_id, guardian_id)
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user