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 ...@@ -33,8 +33,8 @@ class m140506_102106_rbac_init extends \yii\db\Migration
'data' => Schema::TYPE_TEXT, 'data' => Schema::TYPE_TEXT,
'created_at' => Schema::TYPE_INTEGER, 'created_at' => Schema::TYPE_INTEGER,
'updated_at' => Schema::TYPE_INTEGER, 'updated_at' => Schema::TYPE_INTEGER,
'PRIMARY KEY (name)',
], $tableOptions); ], $tableOptions);
$this->addPrimaryKey('pk-auth_rule', $authManager->ruleTable, 'name');
$this->createTable($authManager->itemTable, [ $this->createTable($authManager->itemTable, [
'name' => Schema::TYPE_STRING . '(64) NOT NULL', 'name' => Schema::TYPE_STRING . '(64) NOT NULL',
...@@ -44,26 +44,26 @@ class m140506_102106_rbac_init extends \yii\db\Migration ...@@ -44,26 +44,26 @@ class m140506_102106_rbac_init extends \yii\db\Migration
'data' => Schema::TYPE_TEXT, 'data' => Schema::TYPE_TEXT,
'created_at' => Schema::TYPE_INTEGER, 'created_at' => Schema::TYPE_INTEGER,
'updated_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); ], $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->createIndex('idx-auth_item-type', $authManager->itemTable, 'type');
$this->createTable($authManager->itemChildTable, [ $this->createTable($authManager->itemChildTable, [
'parent' => Schema::TYPE_STRING . '(64) NOT NULL', 'parent' => Schema::TYPE_STRING . '(64) NOT NULL',
'child' => 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); ], $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, [ $this->createTable($authManager->assignmentTable, [
'item_name' => Schema::TYPE_STRING . '(64) NOT NULL', 'item_name' => Schema::TYPE_STRING . '(64) NOT NULL',
'user_id' => Schema::TYPE_STRING . '(64) NOT NULL', 'user_id' => Schema::TYPE_STRING . '(64) NOT NULL',
'created_at' => Schema::TYPE_INTEGER, '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); ], $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() public function down()
......
...@@ -77,18 +77,14 @@ abstract class DbManagerTestCase extends ManagerTestCase ...@@ -77,18 +77,14 @@ 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\base\InvalidParamException
* @throws \yii\db\Exception * @throws \yii\db\Exception
* @throws \yii\base\InvalidConfigException * @throws \yii\base\InvalidConfigException
* @return \yii\db\Connection * @return \yii\db\Connection
*/ */
public static function getConnection($reset = true, $open = true) public static function getConnection()
{ {
if (!$reset && static::$db) { if (static::$db == null) {
return static::$db;
}
$db = new Connection; $db = new Connection;
$db->dsn = static::$database['dsn']; $db->dsn = static::$database['dsn'];
if (isset(static::$database['username'])) { if (isset(static::$database['username'])) {
...@@ -98,11 +94,11 @@ abstract class DbManagerTestCase extends ManagerTestCase ...@@ -98,11 +94,11 @@ abstract class DbManagerTestCase extends ManagerTestCase
if (isset(static::$database['attributes'])) { if (isset(static::$database['attributes'])) {
$db->attributes = static::$database['attributes']; $db->attributes = static::$database['attributes'];
} }
if ($open) { if (!$db->isActive) {
$db->open(); $db->open();
} }
static::$db = $db; 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