<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260203123000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create sites table and link employees to site';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE sites (id SERIAL NOT NULL, name VARCHAR(150) NOT NULL, color VARCHAR(20) NOT NULL, PRIMARY KEY(id))');
        $this->addSql('ALTER TABLE employees ADD site_id INT DEFAULT NULL');
        $this->addSql('CREATE INDEX IDX_EMPLOYEES_SITE ON employees (site_id)');
        $this->addSql('ALTER TABLE employees ADD CONSTRAINT FK_EMPLOYEES_SITE FOREIGN KEY (site_id) REFERENCES sites (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE employees DROP CONSTRAINT FK_EMPLOYEES_SITE');
        $this->addSql('DROP INDEX IDX_EMPLOYEES_SITE');
        $this->addSql('ALTER TABLE employees DROP COLUMN site_id');
        $this->addSql('DROP TABLE sites');
    }
}
