<?php

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

class m160216_155856_cdn_2_0 extends Migration
{
    public function up()
    {
        // champs adresse + credit user
        $this->addColumn('user', 'adresse', Schema::TYPE_TEXT) ;
        $this->addColumn('user', 'credit', Schema::TYPE_FLOAT) ;
        
        // champs commentaire commande
        $this->addColumn('commande', 'commentaire', Schema::TYPE_TEXT) ;
        
        // table credit_historique
        $this->createTable('credit_historique', [
    		'id' => 'pk',
    		'id_user' => Schema::TYPE_INTEGER . ' NOT NULL',
                'id_commande' => Schema::TYPE_INTEGER,
                'date' => Schema::TYPE_DATETIME,
                'montant' => Schema::TYPE_FLOAT,
                'type' => Schema::TYPE_STRING.' NOT NULL'
    	]);
    }

    public function down()
    {
        
        $this->dropColumn('user', 'adresse') ;
        $this->dropColumn('user', 'credit') ;
        
        $this->dropColumn('commande', 'commentaire') ;
        
        $this->dropTable('credit_historique');
    }
    
    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }
    
    public function safeDown()
    {
    }
    */
}