<?php

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

/**
 * Class m240611_125313_create_table_user_message
 */
class m240611_125313_create_table_user_message extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('user_message', [
            'id' => 'pk',
            'id_user' => Schema::TYPE_INTEGER,
            'message' => Schema::TYPE_TEXT,
            'created_at' => Schema::TYPE_DATETIME,
            'created_by' => Schema::TYPE_INTEGER,
            'read_at' => Schema::TYPE_DATETIME,
        ]);
        $this->addForeignKey('fk_user_message_id_user', 'user_message', 'id_user', 'user', 'id');
        $this->addForeignKey('fk_user_message_created_by', 'user_message', 'created_by', 'user', 'id');
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('user_message');
        $this->dropForeignKey('fk_user_message_id_user', 'user_message');
        $this->dropForeignKey('fk_user_message_created_by', 'user_message');
    }
}
