Files
datahub/backend/migrations/2026_03_09_100000_create_roles_table.php
T

39 lines
1.4 KiB
PHP
Raw Normal View History

2026-03-09 10:11:51 +08:00
<?php
use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('roles', function (Blueprint $table) {
$table->id()->comment('主键');
$table->string('name', 50)->unique()->comment('角色标识');
$table->string('label', 100)->comment('显示名称');
$table->text('description')->nullable()->comment('描述');
$table->timestampsTz();
});
// 种子数据
$now = \Carbon\Carbon::now();
\Hyperf\DbConnection\Db::table('roles')->insert([
['name' => 'administrator', 'label' => '超级管理员', 'description' => '拥有系统全部权限', 'created_at' => $now, 'updated_at' => $now],
['name' => 'developer', 'label' => '开发者', 'description' => '数据维护者,拥有所维护平台的全部数据权限', 'created_at' => $now, 'updated_at' => $now],
['name' => 'accessor', 'label' => '数据访问者', 'description' => '按授权范围访问数据,可作为 API 调用用户', 'created_at' => $now, 'updated_at' => $now],
]);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('roles');
}
};