<?php

use yii\db\Migration;

class m160315_022841_add_logs_table extends Migration
{
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $this->createTable(
            'trigger_logs',
            [
                'id' => $this->primaryKey(),
                'user_id' => $this->integer()->notNull(),
                'action' => $this->string(255)->notNull(),
                'datetime' => $this->dateTime()->notNull(),
                'presence_time' => $this->integer(11)->defaultValue(1)
            ]
        );
        $this->addForeignKey(
            'trigger_logs_user_id',
            'trigger_logs', 'user_id',
            'users', 'id'
        );
    }

    public function safeDown()
    {
        $this->dropForeignKey(
            'trigger_logs_user_id',
            'trigger_logs'
        );
        $this->dropTable('trigger_logs');
    }
}
