m150929_113358_change_Importer_dataPrice.php 1011 Bytes
<?php

use yii\db\Schema;
use yii\db\Migration;

class m150929_113358_change_Importer_dataPrice extends Migration
{
    public function safeUp()
    {
        // увеличим размерность строки, так как при преобразовании из таймстампа в дату может не хватить символов
        $this->alterColumn('{{%importers}}','price_date_update','VARCHAR(80)' );
        // конвертем в дату
        $this->update('{{%importers}}',['price_date_update'=> new yii\db\Expression('FROM_UNIXTIME(price_date_update)')]);
        // а из даты в таймстамп
        $this->alterColumn('{{%importers}}','price_date_update','TIMESTAMP NOT NULL' );
        $this->createIndex('price_date', '{{%importers}}', 'price_date_update', false);

    }


    public function safedown()
    {
        $this->alterColumn('{{%importers}}','price_date','varchar(15)' );
        $this->dropIndex('price_date', '{{%importers}}');
    }

}