m180613_101610_alter_package_table.php 1.05 KB
<?php

use yii\db\Migration;

/**
 * Class m180613_101610_alter_package_table
 */
class m180613_101610_alter_package_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
            $this->addColumn('package', 'service_id', $this->integer());
            
            $this->addForeignKey('package_service_fk',
                                'package',
                                'service_id',
                                'service',
                                'id',
                                'SET NULL',
                                'CASCADE');
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropForeignKey('package_service_fk', 'package');
        $this->dropColumn('service_id', 'package');
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m180613_101610_alter_package_table cannot be reverted.\n";

        return false;
    }
    */
}