<?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\Main;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20250425093948 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create a relation between usergroup and user job';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            ALTER TABLE chill_main_user_group ADD userJob_id INT DEFAULT NULL
        SQL);
        $this->addSql(<<<'SQL'
            ALTER TABLE chill_main_user_group ADD CONSTRAINT FK_6576E74D64B65C5B FOREIGN KEY (userJob_id) REFERENCES chill_main_user_job (id) NOT DEFERRABLE INITIALLY IMMEDIATE
        SQL);
        $this->addSql(<<<'SQL'
            CREATE INDEX IDX_6576E74D64B65C5B ON chill_main_user_group (userJob_id)
        SQL);
    }

    public function down(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            ALTER TABLE chill_main_user_group DROP CONSTRAINT FK_6576E74D64B65C5B
        SQL);
        $this->addSql(<<<'SQL'
            DROP INDEX IDX_6576E74D64B65C5B
        SQL);
        $this->addSql(<<<'SQL'
            ALTER TABLE chill_main_user_group DROP userJob_id
        SQL);
    }
}
