m160607_130950_insert_auth_item.php 2.15 KB
<?php

use yii\db\Migration;
use thread\modules\user\User as ParentModule;

/**
 * Class m160607_130950_insert_auth_item
 *
 * @package thread\modules\user
 * @author FilamentV <vortex.filament@gmail.com>
 * @copyright (c) 2016, VipDesign
 */
class m160607_130950_insert_auth_item extends Migration
{

    /**
     * @var string
     */
    public $tableAuthItem = '{{%auth_item}}';

    /**
     * @var string
     */
    public $tableAuthAssignment = '{{%auth_assignment}}';

    /**
     * @var string
     */
    public $tableAuthItemChild = '{{%auth_item_child}}';

    /**
     *
     */
    public function init()
    {
        $this->db = ParentModule::getDb();
        parent::init();
    }

    /**
     * Implement migration
     */
    public function safeUp()
    {
        $this->batchInsert(
            $this->tableAuthItem,
            [
                'name',
                'type',
                'description',
                'rule_name',
                'data',
                'created_at',
                'updated_at',
            ],
            [
                [
                    'name' => 'dev',
                    'type' => 1,
                    'description' => 'developer',
                    'rule_name' => null,
                    'data' => null,
                    'created_at' => time(),
                    'updated_at' => time(),
                ],
                [
                    'name' => 'admin',
                    'type' => 1,
                    'description' => 'admin',
                    'rule_name' => null,
                    'data' => null,
                    'created_at' => time(),
                    'updated_at' => time(),
                ],
                [
                    'name' => 'user',
                    'type' => 1,
                    'description' => 'user',
                    'rule_name' => null,
                    'data' => null,
                    'created_at' => time(),
                    'updated_at' => time(),
                ]
            ]
        );
    }

    /**
     * Cancel migration
     */
    public function safeDown()
    {
        //TODO: m160607_130950_insert_auth_item
    }
}