Blame view

console/migrations/m150929_113358_change_Importer_dataPrice.php 1011 Bytes
942bad48   Mihail   adapt project to ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  <?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}}');
      }
  
  }