<?php

namespace Application\Migrations;

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

/**
 * Auto-generated Migration: Please modify to your needs!
 */
class Version20170805224140 extends AbstractMigration
{
    /**
     * @param Schema $schema
     */
    public function up(Schema $schema)
    {
        // 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('CREATE SEQUENCE operationpee_category_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
        $this->addSql('CREATE TABLE operationpee_category (id INT NOT NULL, name VARCHAR(255) NOT NULL, logo_path VARCHAR(255) DEFAULT NULL, logo_size INT DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_21C671225E237E06 ON operationpee_category (name)');
        $this->addSql('ALTER TABLE operationpee ADD category_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE operationpee ADD CONSTRAINT FK_2299D2B612469DE2 FOREIGN KEY (category_id) REFERENCES operationpee_category (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('CREATE INDEX IDX_2299D2B612469DE2 ON operationpee (category_id)');
    }

    /**
     * @param Schema $schema
     */
    public function down(Schema $schema)
    {
        // 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 OperationPEE DROP CONSTRAINT FK_2299D2B612469DE2');
        $this->addSql('DROP SEQUENCE operationpee_category_id_seq CASCADE');
        $this->addSql('DROP TABLE operationpee_category');
        $this->addSql('DROP INDEX IDX_2299D2B612469DE2');
        $this->addSql('ALTER TABLE OperationPEE DROP category_id');
    }
}
