<?php declare(strict_types = 1);

namespace Application\Migrations;

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

/**
 * Auto-generated Migration: Please modify to your needs!
 */
class Version20171207213636 extends AbstractMigration
{
    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('DROP SEQUENCE distance_id_seq CASCADE');
        $this->addSql('DROP TABLE distance');
    }

    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('CREATE SEQUENCE distance_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
        $this->addSql('CREATE TABLE distance (id INT NOT NULL, prof INT NOT NULL, inge INT NOT NULL, km DOUBLE PRECISION DEFAULT NULL, temps DOUBLE PRECISION DEFAULT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE INDEX idx_e5e4f8d73247e908 ON distance (inge)');
        $this->addSql('CREATE INDEX idx_e5e4f8d75bba70bb ON distance (prof)');
        $this->addSql('ALTER TABLE distance ADD CONSTRAINT fk_e5e4f8d73247e908 FOREIGN KEY (inge) REFERENCES fos_user (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE distance ADD CONSTRAINT fk_e5e4f8d75bba70bb FOREIGN KEY (prof) REFERENCES fos_user (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
    }
}
