Skip to content

Commit ade6129

Browse files
committed
Update m140808_073114_create_auth_item_group_table.php
1 parent 23f6f0d commit ade6129

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

migrations/m140808_073114_create_auth_item_group_table.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,25 @@ public function safeUp()
1111
{
1212
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
1313
}
14-
15-
$this->createTable(Yii::$app->getModule('user-management')->auth_item_group_table, [
16-
'code' => 'varchar(64) NOT NULL',
17-
'name' => 'varchar(255) NOT NULL',
18-
19-
'created_at' => 'int',
20-
'updated_at' => 'int',
21-
'PRIMARY KEY (code)',
22-
23-
], $tableOptions);
24-
25-
$this->addColumn(Yii::$app->getModule('user-management')->auth_item_table, 'group_code', 'varchar(64)');
26-
$this->addForeignKey('fk_auth_item_group_code', Yii::$app->getModule('user-management')->auth_item_table, 'group_code', Yii::$app->getModule('user-management')->auth_item_group_table, 'code', 'SET NULL', 'CASCADE');
14+
15+
// Check if auth_item_group_table Table exist
16+
$table_name = \Yii::$app->getModule('user-management')->auth_item_group_table;
17+
if (\Yii::$app->db->schema->getTableSchema($table_name) === null)
18+
{
19+
// Create auth_item_group_table table
20+
$this->createTable($table_name, [
21+
'code' => 'varchar(64) NOT NULL',
22+
'name' => 'varchar(255) NOT NULL',
23+
24+
'created_at' => 'int',
25+
'updated_at' => 'int',
26+
'PRIMARY KEY (code)',
27+
28+
], $tableOptions);
29+
30+
$this->addColumn(Yii::$app->getModule('user-management')->auth_item_table, 'group_code', 'varchar(64)');
31+
$this->addForeignKey('fk_auth_item_group_code', Yii::$app->getModule('user-management')->auth_item_table, 'group_code', Yii::$app->getModule('user-management')->auth_item_group_table, 'code', 'SET NULL', 'CASCADE');
32+
}
2733

2834
Yii::$app->cache->flush();
2935

0 commit comments

Comments
 (0)