<?php

use yii\db\Migration;

class m160721_152001_create_product_to_rating extends Migration
{
    public function up()
    {
        $this->createTable('product_to_rating', [
            'product_to_rating_id' => $this->primaryKey(),
            'product_id' => $this->integer()->notNull(),
            'value' => $this->float()->defaultValue(0),
        ]);
        
        $this->addForeignKey('product_to_rating_product', 'product_to_rating', 'product_id', 'product', 'product_id', 'CASCADE', 'CASCADE');
    }

    public function down()
    {
        $this->dropForeignKey('product_to_rating_product', 'product_to_rating');
        $this->dropTable('product_to_rating');
    }
}
