Skip to content

Commit 0eb4f2d

Browse files
authored
Merge pull request #6 from windhoney/develop
Develop
2 parents e637bb2 + 2629a16 commit 0eb4f2d

9 files changed

+261
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@
3737
]
3838
],
3939
```
40+
* **创建所需要的表**
41+
```
42+
//用户表user和菜单表menu
43+
yii migrate --migrationPath=@vendor/windhoney/yii2-rest-rbac/migrations
44+
//rbac相关权限表
45+
yii migrate --migrationPath=@yii/rbac/migrations/
46+
//oauth2相关表
47+
yii migrate --migrationPath=@vendor/filsh/yii2-oauth2-server/migrations
48+
```
4049

4150
* **添加路由配置**
4251

components/Configs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class Configs extends \yii\base\Object
5757
/**
5858
* @var string MenuOld table name.
5959
*/
60-
public $menuTable = '{{menu}}';
60+
public $menuTable = 'menu';
6161
/**
62-
* @var string MenuOld table name.
62+
* @var string Menu table name.
6363
*/
6464
public $userTable = 'user';
6565
/**
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
use wind\rest\components\Configs;
4+
5+
/**
6+
* Migration table of table_menu
7+
*
8+
* @author Misbahul D Munir <[email protected]>
9+
* @since 1.0
10+
*/
11+
class m140602_111327_create_menu_table extends \yii\db\Migration
12+
{
13+
14+
/**
15+
* @inheritdoc
16+
*/
17+
public function up()
18+
{
19+
$menuTable = Configs::instance()->menuTable;
20+
$tableOptions = null;
21+
if ($this->db->driverName === 'mysql') {
22+
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
23+
}
24+
25+
$this->createTable($menuTable, [
26+
'id' => $this->primaryKey(),
27+
'name' => $this->string(128)->notNull(),
28+
'parent' => $this->integer(),
29+
'route' => $this->string(),
30+
'order' => $this->integer(),
31+
'data' => $this->binary(),
32+
"FOREIGN KEY ([[parent]]) REFERENCES {$menuTable}([[id]]) ON DELETE SET NULL ON UPDATE CASCADE",
33+
], $tableOptions);
34+
}
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
public function down()
40+
{
41+
$this->dropTable(Configs::instance()->menuTable);
42+
}
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
use yii\db\Migration;
4+
use wind\rest\components\Configs;
5+
6+
class m160312_050000_create_user extends Migration
7+
{
8+
9+
public function up()
10+
{
11+
$tableOptions = null;
12+
if ($this->db->driverName === 'mysql') {
13+
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
14+
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
15+
}
16+
17+
$userTable = Configs::instance()->userTable;
18+
19+
// Check if the table exists
20+
if ($this->db->schema->getTableSchema($userTable, true) === null) {
21+
$this->createTable($userTable, [
22+
'id' => $this->primaryKey(),
23+
'username' => $this->string(32)->notNull(),
24+
'auth_key' => $this->string(32)->notNull(),
25+
'password_hash' => $this->string()->notNull(),
26+
'password_reset_token' => $this->string(),
27+
'email' => $this->string()->notNull(),
28+
'status' => $this->smallInteger()->notNull()->defaultValue(10),
29+
'created_at' => $this->integer()->notNull(),
30+
'updated_at' => $this->integer()->notNull(),
31+
], $tableOptions);
32+
}
33+
}
34+
35+
public function down()
36+
{
37+
$userTable = Configs::instance()->userTable;
38+
if ($this->db->schema->getTableSchema($userTable, true) !== null) {
39+
$this->dropTable($userTable);
40+
}
41+
}
42+
}

migrations/schema-mssql.sql

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Database schema required by yii2-admin.
3+
*
4+
* @author Misbahul D Munir <[email protected]>
5+
* @since 2.5
6+
*/
7+
8+
drop table if exists [menu];
9+
drop table if exists [user];
10+
11+
create table [menu]
12+
(
13+
[id] int IDENTITY PRIMARY KEY,
14+
[name] varchar(128),
15+
[parent] int(11),
16+
[route] varchar(256),
17+
[order] int(11),
18+
[data] text,
19+
foreign key (parent) references [menu]([id]) ON DELETE SET NULL ON UPDATE CASCADE
20+
);
21+
22+
create table [user]
23+
(
24+
[id] int IDENTITY PRIMARY KEY,
25+
[username] varchar(32) NOT NULL,
26+
[auth_key] varchar(32) NOT NULL,
27+
[password_hash] varchar(256) NOT NULL,
28+
[password_reset_token] varchar(256),
29+
[email] varchar(256) NOT NULL,
30+
[status] integer not null default 10,
31+
[created_at] integer not null,
32+
[updated_at] integer not null
33+
);

migrations/schema-mysql.sql

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Database schema required by yii2-admin.
3+
*
4+
* @author Misbahul D Munir <[email protected]>
5+
* @since 2.5
6+
*/
7+
8+
drop table if exists `menu`;
9+
drop table if exists `user` cascade;
10+
11+
create table `menu`
12+
(
13+
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
14+
`name` varchar(128),
15+
`parent` int(11),
16+
`route` varchar(256),
17+
`order` int(11),
18+
`data` blob,
19+
foreign key (`parent`) references `menu`(`id`) ON DELETE SET NULL ON UPDATE CASCADE
20+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
21+
22+
create table `user`
23+
(
24+
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
25+
`username` varchar(32) NOT NULL,
26+
`auth_key` varchar(32) NOT NULL,
27+
`password_hash` varchar(256) NOT NULL,
28+
`password_reset_token` varchar(256),
29+
`email` varchar(256) NOT NULL,
30+
`status` integer not null default 10,
31+
`created_at` integer not null,
32+
`updated_at` integer not null
33+
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

migrations/schema-oci.sql

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Database schema required by yii2-admin.
3+
*
4+
* @author Misbahul D Munir <[email protected]>
5+
* @since 2.5
6+
*/
7+
8+
drop table if exists "menu";
9+
drop table if exists "user";
10+
11+
create table "menu"
12+
(
13+
"id" NUMBER(10) NOT NULL PRIMARY KEY,
14+
"name" varchar(128),
15+
"parent" number(10),
16+
"route" varchar(256),
17+
"order" number(10),
18+
"data" BYTEA,
19+
foreign key (parent) references "menu"("id") ON DELETE SET NULL ON UPDATE CASCADE
20+
);
21+
22+
create table "user"
23+
(
24+
"id" NUMBER(10) NOT NULL PRIMARY KEY,
25+
"username" varchar(32) NOT NULL,
26+
"auth_key" varchar(32) NOT NULL,
27+
"password_hash" varchar(256) NOT NULL,
28+
"password_reset_token" varchar(256),
29+
"email" varchar(256) NOT NULL,
30+
"status" integer not null default 10,
31+
"created_at" number(10) not null,
32+
"updated_at" number(10) not null
33+
);

migrations/schema-pgsql.sql

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Database schema required by yii2-admin.
3+
*
4+
* @author Misbahul D Munir <[email protected]>
5+
* @since 2.5
6+
*/
7+
8+
drop table if exists "menu";
9+
drop table if exists "user";
10+
11+
create table "menu"
12+
(
13+
"id" serial NOT NULL PRIMARY KEY,
14+
"name" varchar(128),
15+
"parent" integer,
16+
"route" varchar(256),
17+
"order" integer,
18+
"data" bytea,
19+
foreign key ("parent") references "menu"("id") ON DELETE SET NULL ON UPDATE CASCADE
20+
);
21+
22+
create table "user"
23+
(
24+
"id" serial NOT NULL PRIMARY KEY,
25+
"username" varchar(32) NOT NULL,
26+
"auth_key" varchar(32) NOT NULL,
27+
"password_hash" varchar(256) NOT NULL,
28+
"password_reset_token" varchar(256),
29+
"email" varchar(256) NOT NULL,
30+
"status" integer not null default 10,
31+
"created_at" integer not null,
32+
"updated_at" integer not null
33+
);

migrations/schema-sqlite.sql

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Database schema required by yii2-admin.
3+
*
4+
* @author Misbahul D Munir <[email protected]>
5+
* @since 2.5
6+
*/
7+
8+
drop table if exists "menu";
9+
drop table if exists "user";
10+
11+
create table "menu"
12+
(
13+
"id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
14+
"name" varchar(128),
15+
"parent" int(11),
16+
"route" varchar(256),
17+
"order" int(11),
18+
"data" LONGBLOB,
19+
foreign key ("parent") references "menu"("id") ON DELETE SET NULL ON UPDATE CASCADE
20+
);
21+
22+
create table "user"
23+
(
24+
"id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
25+
"username" varchar(32) NOT NULL,
26+
"auth_key" varchar(32) NOT NULL,
27+
"password_hash" varchar(256) NOT NULL,
28+
"password_reset_token" varchar(256),
29+
"email" varchar(256) NOT NULL,
30+
"status" integer not null default 10,
31+
"created_at" integer not null,
32+
"updated_at" integer not null
33+
);

0 commit comments

Comments
 (0)