Files
datahub/backend/migrations/2025_11_10_073400_create_companies_table.php
T

41 lines
1.3 KiB
PHP
Raw Normal View History

2025-11-10 15:49:11 +08:00
<?php
use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;
2025-11-13 14:46:37 +08:00
use Hyperf\DbConnection\Db;
2025-11-10 15:49:11 +08:00
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('companies', function (Blueprint $table) {
2025-11-11 09:11:13 +08:00
$table->bigInteger('id')->primary()->comment('公司ID(来自远程)');
2025-11-10 15:49:11 +08:00
$table->string('name')->unique()->comment('公司名 英文');
$table->string('label')->nullable()->default('null')->comment('公司名 中文');
$table->boolean('enabled')->default('true')->comment('激活状态');
2025-11-13 14:46:37 +08:00
$table->jsonb('ext')->nullable()->comment('额外信息');
2025-11-12 09:34:40 +08:00
$table->timestampsTz();
2025-11-13 14:46:37 +08:00
// 索引
$table->index('enabled', 'idx_companies_enabled');
$table->index('created_at', 'idx_companies_created_at');
$table->index('updated_at', 'idx_companies_updated_at');
2025-11-10 15:49:11 +08:00
});
2025-11-13 14:46:37 +08:00
// 为 JSONB 字段创建 GIN 索引,支持高效的 JSON 查询
Db::statement('CREATE INDEX idx_companies_ext ON companies USING GIN (ext)');
2025-11-10 15:49:11 +08:00
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('companies');
}
};