Files
xk-api-yii/console/migrations/m221104_020506_init2.php
2024-09-19 11:32:39 +08:00

183 lines
9.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use yii\db\Migration;
/**
* Class m221104_020506_init2
*/
class m221104_020506_init2 extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('{{%admin}}', [
'id' => $this->primaryKey(),
'username' => $this->char(16)->notNull()->comment('用户名'),
'password' => $this->char(60)->notNull()->comment('密码'),
'role' => $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('角色1为官方管理'),
'mall_id' => $this->integer(11)->notNull()->defaultValue(0)->comment('商城ID'),
'salt' => $this->char(32)->notNull()->comment('密码干扰字符'),
'email' => $this->char(32)->notNull()->defaultValue('')->comment('用户邮箱'),
'mobile' => $this->char(15)->notNull()->defaultValue('')->comment('用户手机'),
'reg_time' => $this->integer(11)->notNull()->defaultValue(0)->comment('注册时间'),
'reg_ip' => $this->bigInteger(20)->notNull()->defaultValue(0)->comment('注册IP'),
'last_login_time' => $this->integer(11)->notNull()->defaultValue(0)->comment('最后登录时间'),
'last_login_ip' => $this->bigInteger(20)->notNull()->defaultValue(0)->comment('最后登录IP'),
'update_time' => $this->integer(11)->notNull()->defaultValue(0)->comment('更新时间'),
'is_sub' => $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('是否子账号'),
'is_delete' => $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('是否删除'),
'status' => $this->tinyInteger(1)->notNull()->defaultValue(1)->comment('用户状态 1正常 0禁用'),
]);
$this->createTable('{{%admin_access_token}}', [
'id' => $this->primaryKey(),
'access_token' => $this->string(60)->notNull()->comment('授权令牌'),
'admin_id' => $this->integer(11)->notNull()->defaultValue(0)->comment('admin用户id'),
'group' => $this->string(100)->notNull()->defaultValue('')->comment('组别'),
'status' => $this->tinyInteger(1)->notNull()->defaultValue(1)->comment('状态[-1:删除;0:禁用;1启用]'),
'expired_at' => $this->integer(11)->notNull()->defaultValue(0)->comment('过期时间'),
'created_at' => $this->integer(11)->notNull()->defaultValue(0)->comment('创建时间'),
'updated_at' => $this->integer(11)->notNull()->defaultValue(0)->comment('修改时间'),
]);
$this->createTable('{{%attachment_group}}', [
'id' => $this->primaryKey(),
'mall_id' => $this->integer(11)->notNull()->defaultValue(0),
'name' => $this->string(64)->notNull()->defaultValue('')->comment('组别'),
'is_delete' => $this->tinyInteger(1)->notNull()->defaultValue(0),
'created_at' => $this->integer(11)->notNull()->defaultValue(0),
'updated_at' => $this->integer(11)->notNull()->defaultValue(0),
'deleted_at' => $this->integer(11)->notNull()->defaultValue(0),
'is_recycle' => $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('是否加入回收站 0.否|1.是'),
'type' => $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('0 图片 1商品'),
]);
$this->createTable('{{%attachment}}', [
'id' => $this->primaryKey(),
'storage_id' => $this->integer(11)->notNull(),
'attachment_group_id' => $this->integer(11)->notNull()->defaultValue(0),
'user_id' => $this->integer(11)->notNull(),
'mall_id' => $this->integer(11)->notNull()->defaultValue(0),
'name' => $this->string(128)->notNull(),
'size' => $this->integer(11)->notNull()->comment('大小:字节'),
'url' => $this->string(2080)->notNull(),
'thumb_url' => $this->string(2080)->notNull()->defaultValue(''),
'type' => $this->tinyInteger(2)->notNull()->comment('类型1=图片2=视频'),
'created_at' => $this->integer(11)->notNull()->defaultValue(0),
'updated_at' => $this->integer(11)->notNull()->defaultValue(0),
'deleted_at' => $this->integer(11)->notNull()->defaultValue(0),
'is_delete' => $this->tinyInteger(2)->notNull()->defaultValue(0),
'is_recycle' => $this->tinyInteger(2)->notNull()->defaultValue(0)->comment('是否加入回收站 0.否|1.是'),
]);
$this->createTable('{{%role}}', [
'id' => $this->primaryKey(),
'name' => $this->string(50),
'role_code' => $this->string(50),
'description' => $this->string(255),
'created_at' => $this->integer(11)->notNull()->defaultValue(0),
'updated_at' => $this->integer(11)->notNull()->defaultValue(0),
]);
$this->createTable('{{%role_menu}}', [
'id' => $this->primaryKey(),
'role_id' => $this->integer(11),
'menuUrl' => $this->string(50),
'created_at' => $this->integer(11)->notNull()->defaultValue(0),
'updated_at' => $this->integer(11)->notNull()->defaultValue(0),
]);
$this->createTable('{{%menu}}', [
// 'id' => $this->primaryKey(),
'menuUrl' => $this->string(50)->notNull()->defaultValue('')->comment('菜单地址'),
'menuName' => $this->string(50)->notNull()->defaultValue('')->comment('菜单名称'),
'parentPath' => $this->string(50)->notNull()->defaultValue('')->comment('上级路由'),
'routeName' => $this->string(50)->notNull()->defaultValue('')->comment('路由name'),
'redirect' => $this->string(255)->notNull()->defaultValue(''),
'icon' => $this->string(50)->defaultValue('')->comment('菜单图标'),
'sort' => $this->integer(11)->notNull()->defaultValue(0),
'cacheable' => $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('是否缓存'),
'hidden' => $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('是否隐藏'),
'affix' => $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('是否固定标题栏'),
]);
$this->addPrimaryKey('menuUrl','{{%menu}}','menuUrl');
$this->createTable('{{%sub_account_menu}}', [
'id' => $this->primaryKey(),
'admin_id' => $this->integer(11),
'menuUrl' => $this->string(50),
'created_at' => $this->integer(11)->notNull()->defaultValue(0),
'updated_at' => $this->integer(11)->notNull()->defaultValue(0),
]);
$this->createTable('{{%config}}', [
'id' => $this->primaryKey(),
'name' => $this->string(30)->notNull()->defaultValue('')->comment('配置名称'),
'title' => $this->string(50)->notNull()->defaultValue('')->comment('配置标题'),
'group' => $this->tinyInteger(3)->notNull()->defaultValue(0)->comment('配置分组'),
'type' => $this->tinyInteger(3)->notNull()->defaultValue(0)->comment('配置类型'),
'value' => $this->text()->comment('配置值'),
'extra' => $this->string(255)->comment('配置值'),
'remark' => $this->string(100)->comment('配置说明'),
'created_at' => $this->integer(11)->notNull()->defaultValue(0),
'updated_at' => $this->integer(11)->notNull()->defaultValue(0),
'sort' => $this->integer(11)->notNull()->defaultValue(0),
'status' => $this->tinyInteger(2)->notNull()->defaultValue(1),
]);
$this->dropTable('{{%user}}');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('{{%admin}}');
$this->dropTable('{{%admin_access_token}}');
$this->dropTable('{{%attachment_group}}');
$this->dropTable('{{%attachment}}');
$this->dropTable('{{%role}}');
$this->dropTable('{{%role_menu}}');
$this->dropTable('{{%menu}}');
$this->dropTable('{{%sub_account_menu}}');
$this->dropTable('{{%config}}');
$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';
}
$this->createTable('{{%user}}', [
'id' => $this->primaryKey(),
'username' => $this->string()->notNull()->unique(),
'auth_key' => $this->string(32)->notNull(),
'password_hash' => $this->string()->notNull(),
'password_reset_token' => $this->string()->unique(),
'email' => $this->string()->notNull()->unique(),
'status' => $this->smallInteger()->notNull()->defaultValue(10),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
'verification_token' => $this->string()->defaultValue(null)
], $tableOptions);
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m221104_020506_init2 cannot be reverted.\n";
return false;
}
*/
}