<?php declare(strict_types=1);

namespace Application\Migrations;

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

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20180809155220 extends AbstractMigration
{
    public function up(Schema $schema) : void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

        $this->addSql('ALTER TABLE fos_user ADD jobcategory VARCHAR(255) DEFAULT NULL');
        $this->addSql('ALTER TABLE fos_user ADD establishmentType VARCHAR(255) DEFAULT NULL');
        $this->addSql('ALTER TABLE fos_user ADD establishmentEducation VARCHAR(255) DEFAULT NULL');
        $this->addSql('ALTER TABLE fos_user ADD establishmentSector VARCHAR(255) DEFAULT NULL');
        $this->addSql('ALTER TABLE fos_user ADD establishmentSectorOther VARCHAR(255) DEFAULT NULL');
        $this->addSql('ALTER TABLE fos_user ADD formation VARCHAR(255) DEFAULT NULL');
        $this->addSql('ALTER TABLE fos_user ADD formationType VARCHAR(255) DEFAULT NULL');
        $this->addSql('ALTER TABLE fos_user RENAME COLUMN detailfunction TO aboutMe');

        $this->addSql('UPDATE fos_user SET aboutMe = aboutMe || chr(10) || detailformation');

        $this->addSql('ALTER TABLE fos_user ADD availabilities TEXT DEFAULT NULL');
        $this->addSql('COMMENT ON COLUMN fos_user.availabilities IS \'(DC2Type:array)\'');
    }

    public function down(Schema $schema) : void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

        $this->addSql('ALTER TABLE fos_user DROP jobcategory');
        $this->addSql('ALTER TABLE fos_user DROP establishmentType');
        $this->addSql('ALTER TABLE fos_user DROP establishmentEducation');
        $this->addSql('ALTER TABLE fos_user DROP establishmentSector');
        $this->addSql('ALTER TABLE fos_user DROP establishmentSectorOther');
        $this->addSql('ALTER TABLE fos_user DROP formation');
        $this->addSql('ALTER TABLE fos_user DROP formationType');
        $this->addSql('ALTER TABLE fos_user RENAME COLUMN aboutMe TO detailfunction');

        $this->addSql('UPDATE fos_user SET detailfunction = REPLACE(detailfunction, chr(10) || detailformation, \'\')');

        $this->addSql('ALTER TABLE fos_user DROP availabilities');
    }
}
