<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use App\Utils\SettingsHelper;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20230714094823 extends AbstractMigration
{
    public function getDescription(): string
    {
        return '';
    }

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('DROP INDEX uniq_e545a0c59f74b898 ON setting');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_9F74B8989F74B898 ON setting (setting)');

        $settHelper = new SettingsHelper();
        $settings = $settHelper->getAll();
        foreach ($settings as $sett) {
            $type = $sett->type;
            $setting = $sett->setting;

            $this->addSql("INSERT INTO setting (setting, value, type) VALUES ('$setting', null, '$type')
                            ON DUPLICATE KEY UPDATE type = '$type'");
        }

    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('DROP INDEX uniq_9f74b8989f74b898 ON setting');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_E545A0C59F74B898 ON setting (setting)');
    }
}
