<?php

namespace Application\Migrations;

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

/**
 * Auto-generated Migration: Please modify to your need!
 */
class Version20120501170249 extends AbstractMigration
{
    public function up(Schema $schema)
    {
        // this up() migration is autogenerated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
        
        $this->addSql("CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(50) NOT NULL, email VARCHAR(100) NOT NULL, password VARCHAR(100) NOT NULL, first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50) NOT NULL, created DATETIME NOT NULL, edited DATETIME NOT NULL, disabled TINYINT(1) NOT NULL, salt VARCHAR(50) NOT NULL, UNIQUE INDEX UNIQ_8D93D649F85E0677 (username), UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) ENGINE = InnoDB");
        $this->addSql("CREATE TABLE user_has_role (user_id INT NOT NULL, role_id INT NOT NULL, INDEX IDX_EAB8B535A76ED395 (user_id), INDEX IDX_EAB8B535D60322AC (role_id), PRIMARY KEY(user_id, role_id)) ENGINE = InnoDB");
        $this->addSql("CREATE TABLE user_has_board (user_id INT NOT NULL, board_id INT NOT NULL, INDEX IDX_A33FB61DA76ED395 (user_id), INDEX IDX_A33FB61DE7EC5785 (board_id), PRIMARY KEY(user_id, board_id)) ENGINE = InnoDB");
        $this->addSql("CREATE TABLE board_column (id INT AUTO_INCREMENT NOT NULL, board_id INT DEFAULT NULL, name VARCHAR(50) NOT NULL, max_issues INT NOT NULL, created DATETIME NOT NULL, edited DATETIME NOT NULL, sorting INT NOT NULL, INDEX IDX_D14DC3D9E7EC5785 (board_id), PRIMARY KEY(id)) ENGINE = InnoDB");
        $this->addSql("CREATE TABLE role (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(50) NOT NULL, description LONGTEXT NOT NULL, created DATETIME NOT NULL, edited DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB");
        $this->addSql("CREATE TABLE issue (id INT AUTO_INCREMENT NOT NULL, created_user_id INT DEFAULT NULL, last_edited_user_id INT DEFAULT NULL, boardcolumn_id INT DEFAULT NULL, name VARCHAR(100) NOT NULL, created DATETIME NOT NULL, edited DATETIME NOT NULL, sorting INT NOT NULL, INDEX IDX_12AD233EE104C1D3 (created_user_id), INDEX IDX_12AD233E2CDA43A (last_edited_user_id), INDEX IDX_12AD233EB9C80C (boardcolumn_id), PRIMARY KEY(id)) ENGINE = InnoDB");
        $this->addSql("CREATE TABLE board (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(50) NOT NULL, description LONGTEXT NOT NULL, created DATETIME NOT NULL, edited DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB");
        $this->addSql("ALTER TABLE user_has_role ADD CONSTRAINT FK_EAB8B535A76ED395 FOREIGN KEY (user_id) REFERENCES user(id)");
        $this->addSql("ALTER TABLE user_has_role ADD CONSTRAINT FK_EAB8B535D60322AC FOREIGN KEY (role_id) REFERENCES role(id)");
        $this->addSql("ALTER TABLE user_has_board ADD CONSTRAINT FK_A33FB61DA76ED395 FOREIGN KEY (user_id) REFERENCES user(id)");
        $this->addSql("ALTER TABLE user_has_board ADD CONSTRAINT FK_A33FB61DE7EC5785 FOREIGN KEY (board_id) REFERENCES board(id)");
        $this->addSql("ALTER TABLE board_column ADD CONSTRAINT FK_D14DC3D9E7EC5785 FOREIGN KEY (board_id) REFERENCES board(id) ON DELETE CASCADE");
        $this->addSql("ALTER TABLE issue ADD CONSTRAINT FK_12AD233EE104C1D3 FOREIGN KEY (created_user_id) REFERENCES user(id) ON DELETE CASCADE");
        $this->addSql("ALTER TABLE issue ADD CONSTRAINT FK_12AD233E2CDA43A FOREIGN KEY (last_edited_user_id) REFERENCES user(id) ON DELETE CASCADE");
        $this->addSql("ALTER TABLE issue ADD CONSTRAINT FK_12AD233EB9C80C FOREIGN KEY (boardcolumn_id) REFERENCES board_column(id) ON DELETE CASCADE");
    }

    public function down(Schema $schema)
    {
        // this down() migration is autogenerated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
        
        $this->addSql("ALTER TABLE user_has_role DROP FOREIGN KEY FK_EAB8B535A76ED395");
        $this->addSql("ALTER TABLE user_has_board DROP FOREIGN KEY FK_A33FB61DA76ED395");
        $this->addSql("ALTER TABLE issue DROP FOREIGN KEY FK_12AD233EE104C1D3");
        $this->addSql("ALTER TABLE issue DROP FOREIGN KEY FK_12AD233E2CDA43A");
        $this->addSql("ALTER TABLE issue DROP FOREIGN KEY FK_12AD233EB9C80C");
        $this->addSql("ALTER TABLE user_has_role DROP FOREIGN KEY FK_EAB8B535D60322AC");
        $this->addSql("ALTER TABLE user_has_board DROP FOREIGN KEY FK_A33FB61DE7EC5785");
        $this->addSql("ALTER TABLE board_column DROP FOREIGN KEY FK_D14DC3D9E7EC5785");
        $this->addSql("DROP TABLE user");
        $this->addSql("DROP TABLE user_has_role");
        $this->addSql("DROP TABLE user_has_board");
        $this->addSql("DROP TABLE board_column");
        $this->addSql("DROP TABLE role");
        $this->addSql("DROP TABLE issue");
        $this->addSql("DROP TABLE board");
    }
}
