<?php

use yii\db\Migration;

class m160323_234304_product_image extends Migration
{
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // Only for MySQL
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

            // @todo https://habrahabr.ru/post/138947/
        } elseif ($this->db->driverName === 'pgsql') {
            // Only for PostgreSQL
            // @todo use intarray field for tax_options
        }

        $this->createTable('{{%product_image}}', [
            'product_image_id' => $this->integer()->notNull(),
            'product_id' => $this->integer()->notNull(),
            'image' => $this->string(255),
            'alt' => $this->string(255),
            'title' => $this->string(255),
        ], $tableOptions);
        $this->addForeignKey('product_image_product_fkey', 'product_image', 'product_id', 'product', 'product_id', 'CASCADE', 'CASCADE');
    }

    public function down()
    {
        $this->dropTable('{{%product_image}}');
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
