modified 完善数据库迁移脚本

This commit is contained in:
zhaoxiang 2019-05-13 16:10:14 +08:00
parent dfe8929abc
commit 31c45c9fdb
9 changed files with 277 additions and 6 deletions

View File

@ -24,6 +24,23 @@ class AdminApp extends Migrator {
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
/**
* CREATE TABLE `admin_app` (
* `id` int(11) unsigned NOT NULL,
* `app_id` varchar(50) NOT NULL DEFAULT '' COMMENT '应用id',
* `app_secret` varchar(50) NOT NULL DEFAULT '' COMMENT '应用密码',
* `app_name` varchar(50) NOT NULL DEFAULT '' COMMENT '应用名称',
* `app_status` int(2) NOT NULL DEFAULT '1' COMMENT '应用状态0表示禁用1表示启用',
* `app_info` text COMMENT '应用说明',
* `app_api` text COMMENT '当前应用允许请求的全部API接口',
* `app_group` varchar(128) NOT NULL DEFAULT 'default' COMMENT '当前应用所属的应用组唯一标识',
* `app_addTime` int(11) NOT NULL DEFAULT '0' COMMENT '应用创建时间',
* `app_api_show` text COMMENT '前台样式显示所需数据格式',
* PRIMARY KEY (`id`),
* UNIQUE KEY `app_id` (`app_id`)
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='appId和appSecret表';
*/
public function change() {
$table = $this->table('admin_app', [
'comment' => 'appId和appSecret表'
@ -54,7 +71,7 @@ class AdminApp extends Migrator {
'limit' => 128,
'default' => 'default',
'comment' => '当前应用所属的应用组唯一标识'
])->addColumn('app_addTime', 'integer', [
])->addColumn('app_add_time', 'integer', [
'limit' => 11,
'default' => 0,
'comment' => '应用创建时间'

View File

@ -24,6 +24,18 @@ class AdminAppGroup extends Migrator {
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
/**
* CREATE TABLE `admin_app_group` (
* `id` int(11) unsigned NOT NULL,
* `name` varchar(128) NOT NULL DEFAULT '' COMMENT '组名称',
* `description` text COMMENT '组说明',
* `status` int(2) NOT NULL DEFAULT '1' COMMENT '组状态0表示禁用1表示启用',
* `hash` varchar(128) NOT NULL DEFAULT '' COMMENT '组标识',
* PRIMARY KEY (`id`)
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用组,目前只做管理使用,没有实际权限控制';
*/
public function change() {
$table = $this->table('admin_app_group', [
'comment' => '应用组,目前只做管理使用,没有实际权限控制'

View File

@ -1,7 +1,6 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class AdminAuthGroup extends Migrator {
/**
@ -25,6 +24,17 @@ class AdminAuthGroup extends Migrator {
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
/**
* CREATE TABLE `admin_auth_group` (
* `id` int(11) unsigned NOT NULL,
* `name` varchar(50) NOT NULL DEFAULT '' COMMENT '组名称',
* `description` text COMMENT '组描述',
* `status` int(2) NOT NULL DEFAULT '1' COMMENT '组状态为1正常为0禁用',
* PRIMARY KEY (`id`)
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='权限组';
*/
public function change() {
$table = $this->table('admin_auth_group', [
'comment' => '权限组'

View File

@ -1,7 +1,6 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class AdminAuthGroupAccess extends Migrator {
/**
@ -25,6 +24,18 @@ class AdminAuthGroupAccess extends Migrator {
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
/**
* CREATE TABLE `admin_auth_group_access` (
* `id` int(11) unsigned NOT NULL,
* `uid` int(11) unsigned NOT NULL DEFAULT '0',
* `groupId` varchar(255) NOT NULL DEFAULT '',
* PRIMARY KEY (`id`),
* KEY `uid` (`uid`),
* KEY `groupId` (`groupId`)
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户和组的对应关系';
*/
public function change() {
$table = $this->table('admin_auth_group_access', [
'comment' => '用户和组的对应关系'

View File

@ -1,7 +1,6 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class AdminAuthRule extends Migrator {
/**
@ -25,6 +24,18 @@ class AdminAuthRule extends Migrator {
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
/**
* CREATE TABLE `admin_auth_rule` (
* `id` int(11) unsigned NOT NULL,
* `url` varchar(80) NOT NULL DEFAULT '' COMMENT '规则唯一标识',
* `groupId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '权限所属组的ID',
* `auth` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '权限数值',
* `status` int(1) NOT NULL DEFAULT '1' COMMENT '状态为1正常为0禁用',
* PRIMARY KEY (`id`)
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='权限细节';
*/
public function change() {
$table = $this->table('admin_auth_rule', [
'comment' => '权限细节'

View File

@ -1,7 +1,6 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class AdminFields extends Migrator {
/**
@ -25,6 +24,24 @@ class AdminFields extends Migrator {
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
/**
* CREATE TABLE `admin_fields` (
* `id` int(11) unsigned NOT NULL,
* `field_name` varchar(50) NOT NULL DEFAULT '' COMMENT '字段名称',
* `hash` varchar(50) NOT NULL DEFAULT '' COMMENT '权限所属组的ID',
* `data_type` int(2) NOT NULL DEFAULT '0' COMMENT '数据类型来源于DataType类库',
* `default` varchar(500) NOT NULL DEFAULT '' COMMENT '默认值',
* `is_must` int(2) NOT NULL DEFAULT '0' COMMENT '是否必须 0为不必须1为必须',
* `range` varchar(500) NOT NULL DEFAULT '' COMMENT '范围Json字符串根据数据类型有不一样的含义',
* `info` varchar(500) NOT NULL DEFAULT '' COMMENT '字段说明',
* `type` int(2) NOT NULL DEFAULT '0' COMMENT '字段用处0为request1为response',
* `show_name` varchar(50) NOT NULL DEFAULT '' COMMENT 'wiki显示用字段',
* PRIMARY KEY (`id`),
* KEY `hash` (`hash`)
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用于保存各个API的字段规则';
*/
public function change() {
$table = $this->table('admin_fields', [
'comment' => '用于保存各个API的字段规则'

View File

@ -1,7 +1,6 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class AdminGroup extends Migrator {
/**
@ -25,6 +24,22 @@ class AdminGroup extends Migrator {
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
/**
* CREATE TABLE `admin_group` (
* `id` int(11) unsigned NOT NULL,
* `name` varchar(128) NOT NULL DEFAULT '' COMMENT '组名称',
* `description` text COMMENT '组说明',
* `status` int(1) NOT NULL DEFAULT '1' COMMENT '状态为1正常为0禁用',
* `hash` varchar(128) NOT NULL DEFAULT '' COMMENT '组标识',
* `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
* `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
* `image` varchar(256) DEFAULT NULL COMMENT '分组封面图',
* `hot` int(11) NOT NULL DEFAULT '0' COMMENT '分组热度',
* PRIMARY KEY (`id`)
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='接口组管理';
*/
public function change() {
$table = $this->table('admin_group', [
'comment' => '接口组管理'

View File

@ -0,0 +1,94 @@
<?php
use think\migration\Migrator;
class AdminList extends Migrator {
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
/**
* CREATE TABLE `admin_list` (
* `id` int(11) unsigned NOT NULL,
* `api_class` varchar(50) NOT NULL DEFAULT '' COMMENT 'api索引保存了类和方法',
* `hash` varchar(50) NOT NULL DEFAULT '' COMMENT 'api唯一标识',
* `access_token` int(2) NOT NULL DEFAULT '1' COMMENT '是否需要认证AccessToken 1需要0不需要',
* `need_login` int(2) NOT NULL DEFAULT '1' COMMENT '是否需要认证用户token 1需要 0不需要',
* `status` int(2) NOT NULL DEFAULT '1' COMMENT 'API状态0表示禁用1表示启用',
* `method` int(2) NOT NULL DEFAULT '2' COMMENT '请求方式0不限1Post2Get',
* `info` varchar(500) NOT NULL DEFAULT '' COMMENT 'api中文说明',
* `is_test` int(2) NOT NULL DEFAULT '0' COMMENT '是否是测试模式0:生产模式1测试模式',
* `return_str` text COMMENT '返回数据示例',
* `group_hash` varchar(64) NOT NULL DEFAULT 'default' COMMENT '当前接口所属的接口分组',
* PRIMARY KEY (`id`),
* KEY `hash` (`hash`)
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用于维护接口信息';
*/
public function change() {
$table = $this->table('admin_list', [
'comment' => '用于维护接口信息'
])->setCollation('utf8mb4_general_ci');
$table->addColumn('api_class', 'string', [
'limit' => 50,
'default' => '',
'comment' => 'api索引保存了类和方法'
])->addColumn('hash', 'string', [
'limit' => 50,
'default' => '',
'comment' => 'api唯一标识'
])->addColumn('access_token', 'integer', [
'limit' => 2,
'default' => 1,
'comment' => '是否需要认证AccessToken 1需要0不需要'
])->addColumn('need_login', 'integer', [
'limit' => 2,
'default' => 1,
'comment' => '是否需要认证用户token 1需要 0不需要'
])->addColumn('status', 'integer', [
'limit' => 2,
'default' => 1,
'comment' => 'API状态0表示禁用1表示启用'
])->addColumn('method', 'integer', [
'limit' => 2,
'default' => 2,
'comment' => '请求方式0不限1Post2Get'
])->addColumn('info', 'string', [
'limit' => 500,
'default' => '',
'comment' => 'api中文说明'
])->addColumn('is_test', 'integer', [
'limit' => 2,
'default' => 0,
'comment' => '是否是测试模式0:生产模式1测试模式'
])->addColumn('return_str', 'text', [
'null' => true,
'comment' => '返回数据示例'
])->addColumn('group_hash', 'string', [
'limit' => 64,
'default' => 'default',
'comment' => '当前接口所属的接口分组'
])->addIndex(['hash'])->create();
$table->changeColumn('id', 'integer', ['signed' => false]);
}
}

View File

@ -0,0 +1,84 @@
<?php
use think\migration\Migrator;
class AdminMenu extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
/**
* CREATE TABLE `admin_menu` (
* `id` int(11) unsigned NOT NULL,
* `name` varchar(50) NOT NULL DEFAULT '' COMMENT '菜单名',
* `fid` int(11) NOT NULL DEFAULT '0' COMMENT '父级菜单ID',
* `url` varchar(50) NOT NULL DEFAULT '' COMMENT '链接',
* `auth` int(2) NOT NULL DEFAULT '0' COMMENT '访客权限',
* `sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序',
* `hide` int(2) NOT NULL DEFAULT '0' COMMENT '是否显示',
* `icon` varchar(50) NOT NULL DEFAULT '' COMMENT '菜单图标',
* `level` int(2) NOT NULL DEFAULT '0' COMMENT '菜单认证等级',
* PRIMARY KEY (`id`)
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='目录信息';
*/
public function change() {
$table = $this->table('admin_menu', [
'comment' => '目录信息'
])->setCollation('utf8mb4_general_ci');
$table->addColumn('name', 'string', [
'limit' => 50,
'default' => '',
'comment' => '菜单名'
])->addColumn('fid', 'integer', [
'limit' => 11,
'default' => 0,
'comment' => '父级菜单ID'
])->addColumn('url', 'string', [
'limit' => 50,
'default' => '',
'comment' => '链接'
])->addColumn('auth', 'integer', [
'limit' => 2,
'default' => 0,
'comment' => '访客权限'
])->addColumn('sort', 'integer', [
'limit' => 11,
'default' => 0,
'comment' => '排序'
])->addColumn('hide', 'integer', [
'limit' => 2,
'default' => 0,
'comment' => '是否显示'
])->addColumn('icon', 'string', [
'limit' => 50,
'default' => '',
'comment' => '菜单图标'
])->addColumn('level', 'integer', [
'limit' => 2,
'default' => 0,
'comment' => '菜单认证等级'
])->create();
$table->changeColumn('id', 'integer', ['signed' => false]);
}
}