Skip to content

Commit b56c143

Browse files
author
Igor Chepurnoy
committed
add rbac migrations, update init migration, add Migration class
1 parent f989ef0 commit b56c143

File tree

7 files changed

+274
-225
lines changed

7 files changed

+274
-225
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ the installed application. You only need to do these once for all.
7272

7373
1. Create a new database and adjust the `components['db']` configuration in `config/common-local.php` accordingly.
7474

75-
2. Apply migrations with console command `php yii migrate`.
75+
2. Apply migrations:
76+
- `php yii migrate` - create default tables for application
77+
- `php yii migrate --migrationPath=@yii/rbac/migrations` - create rbac tables
78+
- `php yii rbac/migrate` - create roles, permissions and rules
7679

7780
3. Set document root of your web server to `/path/to/application/web/` folder.
7881

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "yii2mod/base",
33
"description": "Base application template for Yii2",
4+
"keywords": ["yii2mod", "base", "project template", "yii2", "framework", "basic"],
45
"homepage": "https://github.com/yii2mod/base/",
5-
"type": "yii-extension",
6+
"type": "project",
67
"license": "MIT",
78
"authors": [
89
{
@@ -18,7 +19,7 @@
1819
"minimum-stability": "dev",
1920
"require": {
2021
"php": ">=5.4.0",
21-
"yiisoft/yii2": ">=2.0.5",
22+
"yiisoft/yii2": ">=2.0.8",
2223
"yiisoft/yii2-bootstrap": "*",
2324
"yiisoft/yii2-swiftmailer": "*",
2425
"yii2mod/yii2-cms": "*",

config/console.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
'id' => 'console',
77
'controllerNamespace' => 'app\commands',
88
'controllerMap' => [
9-
'rbac' => 'yii2mod\rbac\commands\RbacCommand'
9+
'migrate' => [
10+
'class' => 'yii\console\controllers\MigrateController',
11+
'templateFile' => '@app/views/migration.php',
12+
],
1013
],
1114
'components' => [
1215
'errorHandler' => [
@@ -21,6 +24,11 @@
2124
'baseUrl' => 'http://localhost',
2225
],
2326
],
27+
'modules' => [
28+
'rbac' => [
29+
'class' => 'yii2mod\rbac\ConsoleModule'
30+
]
31+
]
2432
];
2533

2634
if (YII_ENV_DEV) {

migrations/Migration.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace app\migrations;
4+
5+
use Yii;
6+
7+
/**
8+
* Class Migration
9+
* @package app\migrations
10+
*/
11+
class Migration extends \yii\db\Migration
12+
{
13+
/**
14+
* @var string
15+
*/
16+
protected $tableOptions;
17+
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function init()
22+
{
23+
parent::init();
24+
25+
switch (Yii::$app->db->driverName) {
26+
case 'mysql':
27+
$this->tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
28+
break;
29+
case 'pgsql':
30+
$this->tableOptions = null;
31+
break;
32+
default:
33+
throw new \RuntimeException('Your database is not supported!');
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)