Last active
January 3, 2016 18:09
-
-
Save anaspk/8500073 to your computer and use it in GitHub Desktop.
A Yii migration to create RBAC tables in the currently configured database.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class m140108_152635_create_rbac_tables extends CDbMigration { | |
public function up() { | |
$this->createTable('AuthItem', array( | |
'name' => 'string NOT NULL', | |
'type' => 'integer NOT NULL', | |
'description' => 'text', | |
'bizrule' => 'text', | |
'data' => 'text', | |
)); | |
$this->addPrimaryKey('auth_item_pk', 'AuthItem', 'name'); | |
$this->createTable('AuthItemChild', array( | |
'parent' => 'string NOT NULL', | |
'child' => 'string NOT NULL', | |
)); | |
$this->addPrimaryKey('auth_item_child_pk', 'AuthItemChild', 'parent, child'); | |
$this->addForeignKey('auth_item_child_parent_fk', 'AuthItemChild', 'parent', 'AuthItem', 'name', 'CASCADE', 'CASCADE'); | |
$this->addForeignKey('auth_item_child_child_fk', 'AuthItemChild', 'child', 'AuthItem', 'name', 'CASCADE', 'CASCADE'); | |
$this->createTable('AuthAssignment', array( | |
'itemname' => 'string NOT NULL', | |
'userid' => 'string NOT NULL', | |
'bizrule' => 'text', | |
'data' => 'text', | |
)); | |
$this->addPrimaryKey('auth_assignment_pk', 'AuthAssignment', 'itemname, userid'); | |
$this->addForeignKey('auth_assignment_item_fk', 'AuthAssignment', 'itemname', 'AuthItem', 'name', 'CASCADE', 'CASCADE'); | |
} | |
public function down() { | |
$this->dropTable('AuthAssignment'); | |
$this->dropTable('AuthItemChild'); | |
$this->dropTable('AuthItem'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment