<?php

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

/**
 * Class m230717_120138_module_ticket
 */
class m230717_120138_module_ticket extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('ticket', [
            'id' => 'pk',
            'id_producer' => Schema::TYPE_INTEGER.' NOT NULL',
            'id_user' => Schema::TYPE_INTEGER.' NOT NULL',
            'subject' => Schema::TYPE_STRING.' NOT NULL',
            'status' => Schema::TYPE_STRING.' NOT NULL',
            'created_at' => Schema::TYPE_DATETIME.' NOT NULL DEFAULT CURRENT_TIMESTAMP',
            'updated_at' => Schema::TYPE_DATETIME.' NOT NULL DEFAULT CURRENT_TIMESTAMP'
        ]);

        $this->createTable('ticket_message', [
            'id' => 'pk',
            'id_ticket' => Schema::TYPE_INTEGER.' NOT NULL',
            'id_user' => Schema::TYPE_INTEGER.' NOT NULL',
            'message' => Schema::TYPE_TEXT.' NOT NULL',
            'created_at' => Schema::TYPE_DATETIME.' NOT NULL DEFAULT CURRENT_TIMESTAMP',
            'updated_at' => Schema::TYPE_DATETIME.' NOT NULL DEFAULT CURRENT_TIMESTAMP',
        ]);

        $this->createTable('ticket_user', [
            'id' => 'pk',
            'id_user' => Schema::TYPE_INTEGER.' NOT NULL',
            'id_ticket' => Schema::TYPE_INTEGER.' NOT NULL',
            'read_at' => Schema::TYPE_DATETIME.' NOT NULL DEFAULT CURRENT_TIMESTAMP',
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('ticket');
        $this->dropTable('ticket_message');
        $this->dropTable('ticket_user');
    }
}
