<?php

use yii\db\Migration;

/**
 * Class m221227_033116_add_gallery_table
 */
class m221227_033116_add_gallery_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable("{{%gallery}}",[
           "id"=>$this->primaryKey(),
            "name"=>$this->string(),
            "description"=>$this->string(),
            "created_at"=>$this->dateTime(),
            "post_id"=>$this->integer(10)->unsigned()
        ]);
        $this->createTable("{{%gallery_item}}",[
            "id"=>$this->primaryKey(),
            "name"=>$this->string(),
            "description"=>$this->string(),
            "created_at"=>$this->dateTime(),
            "gallery_id"=>$this->integer(),
            "path"=>$this->string(),
            "ext"=>$this->string()
        ]);
        $this->addForeignKey("gallery_to_post_fk","{{%gallery}}",'post_id','{{%news}}','id','CASCADE','CASCADE');
        $this->addForeignKey("gallery_item_to_gallery_fk","{{%gallery_item}}",'gallery_id','{{%gallery}}','id','CASCADE','CASCADE');

    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        echo "m221227_033116_add_gallery_table cannot be reverted.\n";

        return false;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m221227_033116_add_gallery_table cannot be reverted.\n";

        return false;
    }
    */
}
