mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-06 21:02:48 +08:00
feat(api-key): add api_key table, source fields, model and auth middleware
This commit is contained in:
47
database/migrations/20260426235556_create_table_api_key.php
Normal file
47
database/migrations/20260426235556_create_table_api_key.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use app\common\ColumnFormat;
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
|
||||
class CreateTableApiKey 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.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('api_key', ['comment' => 'API密钥表', 'signed' => false]);
|
||||
$table->addColumn('admin_id', 'integer', ['limit' => 10, 'signed' => false, 'comment' => '关联管理员ID']);
|
||||
$table->addColumn('api_key', 'string', ['limit' => 64, 'comment' => 'API密钥(md5哈希)']);
|
||||
$table->addColumn(ColumnFormat::stringNormal('name')->setComment('API Key名称/备注'));
|
||||
$table->addColumn(ColumnFormat::integerTypeStatus('status', 1)->setComment('状态,0:禁用,1:启用'));
|
||||
$table->addColumn(ColumnFormat::integerTypeStatus('can_write_own')->setComment('可写自己的,0:不可,1:可'));
|
||||
$table->addColumn(ColumnFormat::integerTypeStatus('can_write_other')->setComment('可写其他的,0:不可,1:可'));
|
||||
$table->addColumn(ColumnFormat::integerTypeStatus('can_delete')->setComment('删除权限,0:不可删除,1:仅删API数据,2:可删所有'));
|
||||
$table->addColumn(ColumnFormat::timestamp('create_time'));
|
||||
$table->addColumn(ColumnFormat::timestamp('update_time'));
|
||||
$table->addColumn(ColumnFormat::timestamp('delete_time'));
|
||||
$table->addIndex('admin_id');
|
||||
$table->addIndex('api_key', ['unique' => true]);
|
||||
$table->create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use app\common\ColumnFormat;
|
||||
use think\migration\Migrator;
|
||||
|
||||
class AddSourceToPostAndUploadFiles 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.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$post = $this->table('post');
|
||||
$post->addColumn(ColumnFormat::stringShort('source')->setDefault('admin')->setComment('来源'))
|
||||
->update();
|
||||
|
||||
$uploadFiles = $this->table('upload_files');
|
||||
$uploadFiles->addColumn(ColumnFormat::stringShort('source')->setDefault('admin')->setComment('来源'))
|
||||
->update();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user