<?php

namespace Application\Migrations;

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

/**
 * Auto-generated Migration: Please modify to your needs!
 */
class Version20170829161036 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() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('CREATE TABLE history (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, qualification_id INT DEFAULT NULL, total_points INT NOT NULL, points INT NOT NULL, created_at DATETIME NOT NULL, INDEX IDX_27BA704BA76ED395 (user_id), INDEX IDX_27BA704B1A75EE38 (qualification_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('ALTER TABLE history ADD CONSTRAINT FK_27BA704BA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
        $this->addSql('ALTER TABLE history ADD CONSTRAINT FK_27BA704B1A75EE38 FOREIGN KEY (qualification_id) REFERENCES qualification (id)');
        $this->addSql('ALTER TABLE question CHANGE id id INT AUTO_INCREMENT NOT NULL, CHANGE query query LONGTEXT NOT NULL, CHANGE answerA answerA LONGTEXT NOT NULL, CHANGE answerB answerB LONGTEXT NOT NULL, CHANGE answerC answerC LONGTEXT NOT NULL, CHANGE answerD answerD LONGTEXT NOT NULL');
    }

    /**
     * @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() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('DROP TABLE history');
        $this->addSql('ALTER TABLE question CHANGE id id INT AUTO_INCREMENT NOT NULL, CHANGE query query LONGTEXT NOT NULL COLLATE utf8_unicode_ci, CHANGE answerA answerA LONGTEXT NOT NULL COLLATE utf8_unicode_ci, CHANGE answerB answerB LONGTEXT NOT NULL COLLATE utf8_unicode_ci, CHANGE answerC answerC LONGTEXT NOT NULL COLLATE utf8_unicode_ci, CHANGE answerD answerD LONGTEXT NOT NULL COLLATE utf8_unicode_ci');
    }
}
