<?php

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

class m160217_124741_add_sessions_table extends Migration
{
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $this->createTable('sessions', [
            'id' => Schema::TYPE_PK,
            'PHPSESSID' => Schema::TYPE_STRING . '(32) NOT NULL',
            'user_id' => Schema::TYPE_INTEGER . '(11) DEFAULT NULL',
            'ip' => Schema::TYPE_STRING . '(15) NOT NULL',
            'url' => Schema::TYPE_TEXT . ' DEFAULT NULL',
            'referer' => Schema::TYPE_TEXT . ' DEFAULT NULL',
            'created_at' => Schema::TYPE_INTEGER . '(11) DEFAULT NULL',
        ]);

        $this->createIndex('sessions_PHPSESSID', 'sessions', 'PHPSESSID');
    }

    public function safeDown()
    {
        $this->dropIndex('sessions_PHPSESSID', 'sessions');

        $this->dropTable('sessions');
    }
}
