<?php

use yii\db\Migration;

class m160512_151201_update_the_cases_schedule_table extends Migration
{
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $this->dropForeignKey(
            'fk_cases_schedule_user',
            'cases_schedule'
        );
        $this->alterColumn(
            'cases_schedule',
            'user_id',
            $this->integer(11)->defaultValue(null)
        );
        $this->addForeignKey(
            'fk_cases_schedule_user',
            'cases_schedule', 'user_id',
            'users', 'id'
        );
        $this->addColumn(
            'cases_schedule',
            'email',
            'varchar(255) NOT NULL'
        );
    }

    public function safeDown()
    {
        $this->dropForeignKey(
            'fk_cases_schedule_user',
            'cases_schedule'
        );
        $this->alterColumn(
            'cases_schedule',
            'user_id',
            $this->integer(11)->notNull()
        );
        $this->addForeignKey(
            'fk_cases_schedule_user',
            'cases_schedule', 'user_id',
            'users', 'id'
        );
        $this->dropColumn(
            'cases_schedule',
            'email'
        );
    }
}
