Skip to content

Commit

Permalink
Merge pull request #6 from windhoney/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
windhoney authored Sep 22, 2017
2 parents e637bb2 + 2629a16 commit 0eb4f2d
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
]
],
```
* **创建所需要的表**
```
//用户表user和菜单表menu
yii migrate --migrationPath=@vendor/windhoney/yii2-rest-rbac/migrations
//rbac相关权限表
yii migrate --migrationPath=@yii/rbac/migrations/
//oauth2相关表
yii migrate --migrationPath=@vendor/filsh/yii2-oauth2-server/migrations
```

* **添加路由配置**

Expand Down
4 changes: 2 additions & 2 deletions components/Configs.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class Configs extends \yii\base\Object
/**
* @var string MenuOld table name.
*/
public $menuTable = '{{menu}}';
public $menuTable = 'menu';
/**
* @var string MenuOld table name.
* @var string Menu table name.
*/
public $userTable = 'user';
/**
Expand Down
43 changes: 43 additions & 0 deletions migrations/m140602_111327_create_menu_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

use wind\rest\components\Configs;

/**
* Migration table of table_menu
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 1.0
*/
class m140602_111327_create_menu_table extends \yii\db\Migration
{

/**
* @inheritdoc
*/
public function up()
{
$menuTable = Configs::instance()->menuTable;
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}

$this->createTable($menuTable, [
'id' => $this->primaryKey(),
'name' => $this->string(128)->notNull(),
'parent' => $this->integer(),
'route' => $this->string(),
'order' => $this->integer(),
'data' => $this->binary(),
"FOREIGN KEY ([[parent]]) REFERENCES {$menuTable}([[id]]) ON DELETE SET NULL ON UPDATE CASCADE",
], $tableOptions);
}

/**
* @inheritdoc
*/
public function down()
{
$this->dropTable(Configs::instance()->menuTable);
}
}
42 changes: 42 additions & 0 deletions migrations/m160312_050000_create_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

use yii\db\Migration;
use wind\rest\components\Configs;

class m160312_050000_create_user extends Migration
{

public function up()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}

$userTable = Configs::instance()->userTable;

// Check if the table exists
if ($this->db->schema->getTableSchema($userTable, true) === null) {
$this->createTable($userTable, [
'id' => $this->primaryKey(),
'username' => $this->string(32)->notNull(),
'auth_key' => $this->string(32)->notNull(),
'password_hash' => $this->string()->notNull(),
'password_reset_token' => $this->string(),
'email' => $this->string()->notNull(),
'status' => $this->smallInteger()->notNull()->defaultValue(10),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
}
}

public function down()
{
$userTable = Configs::instance()->userTable;
if ($this->db->schema->getTableSchema($userTable, true) !== null) {
$this->dropTable($userTable);
}
}
}
33 changes: 33 additions & 0 deletions migrations/schema-mssql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Database schema required by yii2-admin.
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 2.5
*/

drop table if exists [menu];
drop table if exists [user];

create table [menu]
(
[id] int IDENTITY PRIMARY KEY,
[name] varchar(128),
[parent] int(11),
[route] varchar(256),
[order] int(11),
[data] text,
foreign key (parent) references [menu]([id]) ON DELETE SET NULL ON UPDATE CASCADE
);

create table [user]
(
[id] int IDENTITY PRIMARY KEY,
[username] varchar(32) NOT NULL,
[auth_key] varchar(32) NOT NULL,
[password_hash] varchar(256) NOT NULL,
[password_reset_token] varchar(256),
[email] varchar(256) NOT NULL,
[status] integer not null default 10,
[created_at] integer not null,
[updated_at] integer not null
);
33 changes: 33 additions & 0 deletions migrations/schema-mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Database schema required by yii2-admin.
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 2.5
*/

drop table if exists `menu`;
drop table if exists `user` cascade;

create table `menu`
(
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` varchar(128),
`parent` int(11),
`route` varchar(256),
`order` int(11),
`data` blob,
foreign key (`parent`) references `menu`(`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

create table `user`
(
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` varchar(32) NOT NULL,
`auth_key` varchar(32) NOT NULL,
`password_hash` varchar(256) NOT NULL,
`password_reset_token` varchar(256),
`email` varchar(256) NOT NULL,
`status` integer not null default 10,
`created_at` integer not null,
`updated_at` integer not null
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
33 changes: 33 additions & 0 deletions migrations/schema-oci.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Database schema required by yii2-admin.
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 2.5
*/

drop table if exists "menu";
drop table if exists "user";

create table "menu"
(
"id" NUMBER(10) NOT NULL PRIMARY KEY,
"name" varchar(128),
"parent" number(10),
"route" varchar(256),
"order" number(10),
"data" BYTEA,
foreign key (parent) references "menu"("id") ON DELETE SET NULL ON UPDATE CASCADE
);

create table "user"
(
"id" NUMBER(10) NOT NULL PRIMARY KEY,
"username" varchar(32) NOT NULL,
"auth_key" varchar(32) NOT NULL,
"password_hash" varchar(256) NOT NULL,
"password_reset_token" varchar(256),
"email" varchar(256) NOT NULL,
"status" integer not null default 10,
"created_at" number(10) not null,
"updated_at" number(10) not null
);
33 changes: 33 additions & 0 deletions migrations/schema-pgsql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Database schema required by yii2-admin.
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 2.5
*/

drop table if exists "menu";
drop table if exists "user";

create table "menu"
(
"id" serial NOT NULL PRIMARY KEY,
"name" varchar(128),
"parent" integer,
"route" varchar(256),
"order" integer,
"data" bytea,
foreign key ("parent") references "menu"("id") ON DELETE SET NULL ON UPDATE CASCADE
);

create table "user"
(
"id" serial NOT NULL PRIMARY KEY,
"username" varchar(32) NOT NULL,
"auth_key" varchar(32) NOT NULL,
"password_hash" varchar(256) NOT NULL,
"password_reset_token" varchar(256),
"email" varchar(256) NOT NULL,
"status" integer not null default 10,
"created_at" integer not null,
"updated_at" integer not null
);
33 changes: 33 additions & 0 deletions migrations/schema-sqlite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Database schema required by yii2-admin.
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 2.5
*/

drop table if exists "menu";
drop table if exists "user";

create table "menu"
(
"id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
"name" varchar(128),
"parent" int(11),
"route" varchar(256),
"order" int(11),
"data" LONGBLOB,
foreign key ("parent") references "menu"("id") ON DELETE SET NULL ON UPDATE CASCADE
);

create table "user"
(
"id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
"username" varchar(32) NOT NULL,
"auth_key" varchar(32) NOT NULL,
"password_hash" varchar(256) NOT NULL,
"password_reset_token" varchar(256),
"email" varchar(256) NOT NULL,
"status" integer not null default 10,
"created_at" integer not null,
"updated_at" integer not null
);

0 comments on commit 0eb4f2d

Please sign in to comment.