<?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);
    }
}
