Commit ef4d9683 by Alexander Makarov

Fixed RBAC migration for SQLite

parent 905e39ed
......@@ -33,8 +33,8 @@ class m140506_102106_rbac_init extends \yii\db\Migration
'data' => Schema::TYPE_TEXT,
'created_at' => Schema::TYPE_INTEGER,
'updated_at' => Schema::TYPE_INTEGER,
'PRIMARY KEY (name)',
], $tableOptions);
$this->addPrimaryKey('pk-auth_rule', $authManager->ruleTable, 'name');
$this->createTable($authManager->itemTable, [
'name' => Schema::TYPE_STRING . '(64) NOT NULL',
......@@ -44,26 +44,26 @@ class m140506_102106_rbac_init extends \yii\db\Migration
'data' => Schema::TYPE_TEXT,
'created_at' => Schema::TYPE_INTEGER,
'updated_at' => Schema::TYPE_INTEGER,
'PRIMARY KEY (name)',
'FOREIGN KEY (rule_name) REFERENCES ' . $authManager->ruleTable . ' (name) ON DELETE SET NULL ON UPDATE CASCADE',
], $tableOptions);
$this->addPrimaryKey('pk-auth_item', $authManager->itemTable, 'name');
$this->addForeignKey('fk-auth_item-rule_name', $authManager->itemTable, 'rule_name', $authManager->ruleTable, 'name', 'SET NULL', 'CASCADE');
$this->createIndex('idx-auth_item-type', $authManager->itemTable, 'type');
$this->createTable($authManager->itemChildTable, [
'parent' => Schema::TYPE_STRING . '(64) NOT NULL',
'child' => Schema::TYPE_STRING . '(64) NOT NULL',
'PRIMARY KEY (parent, child)',
'FOREIGN KEY (parent) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE',
'FOREIGN KEY (child) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE',
], $tableOptions);
$this->addPrimaryKey('pk-auth_item_child', $authManager->itemChildTable, ['parent', 'child']);
$this->addForeignKey('fk-auth_item_child-parent', $authManager->itemChildTable, 'parent', $authManager->itemTable, 'name', 'CASCADE', 'CASCADE');
$this->addForeignKey('fk-auth_item_child-child', $authManager->itemChildTable, 'child', $authManager->itemTable, 'name', 'CASCADE', 'CASCADE');
$this->createTable($authManager->assignmentTable, [
'item_name' => Schema::TYPE_STRING . '(64) NOT NULL',
'user_id' => Schema::TYPE_STRING . '(64) NOT NULL',
'created_at' => Schema::TYPE_INTEGER,
'PRIMARY KEY (item_name, user_id)',
'FOREIGN KEY (item_name) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE',
], $tableOptions);
$this->addPrimaryKey('pk-auth_assignment', $authManager->assignmentTable, ['item_name', 'user_id']);
$this->addForeignKey('fk-auth_assignment-item_name', $authManager->assignmentTable, 'item_name', $authManager->itemTable, 'name', 'CASCADE', 'CASCADE');
}
public function down()
......
......@@ -77,32 +77,28 @@ abstract class DbManagerTestCase extends ManagerTestCase
}
/**
* @param boolean $reset whether to clean up the test database
* @param boolean $open whether to open and populate test database
* @throws \yii\base\InvalidParamException
* @throws \yii\db\Exception
* @throws \yii\base\InvalidConfigException
* @return \yii\db\Connection
*/
public static function getConnection($reset = true, $open = true)
public static function getConnection()
{
if (!$reset && static::$db) {
return static::$db;
if (static::$db == null) {
$db = new Connection;
$db->dsn = static::$database['dsn'];
if (isset(static::$database['username'])) {
$db->username = static::$database['username'];
$db->password = static::$database['password'];
}
if (isset(static::$database['attributes'])) {
$db->attributes = static::$database['attributes'];
}
if (!$db->isActive) {
$db->open();
}
static::$db = $db;
}
$db = new Connection;
$db->dsn = static::$database['dsn'];
if (isset(static::$database['username'])) {
$db->username = static::$database['username'];
$db->password = static::$database['password'];
}
if (isset(static::$database['attributes'])) {
$db->attributes = static::$database['attributes'];
}
if ($open) {
$db->open();
}
static::$db = $db;
return $db;
return static::$db;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment