2026_03_04_172400_create_leagues_table.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. */
  10. public function up(): void
  11. {
  12. Schema::create('leagues', function (Blueprint $table) {
  13. $table->id();
  14. // 来自 API 的联赛唯一标识
  15. $table->unsignedBigInteger('league_id')->unique()->comment('API-Sports 联赛唯一ID');
  16. // 联赛基本信息
  17. $table->string('name', 100)->comment('联赛名称 e.g. "Ligue 2", "Premier League"');
  18. $table->string('type', 50)->nullable()->comment('League / Cup 等');
  19. $table->string('logo', 255)->nullable()->comment('联赛logo URL');
  20. // 国家信息(扁平化,方便按国家筛选)
  21. $table->string('country_name', 100)->comment('国家名称');
  22. $table->string('country_code', 25)->nullable()->comment('国家代码');
  23. $table->string('country_flag', 255)->nullable()->comment('国旗 SVG/PNG URL');
  24. // 赛季信息 - 直接存 JSON 数组
  25. // 示例结构:[{"year":2010,"start":"2010-08-06","end":"2011-05-20","current":false,"coverage":{...}}, ...]
  26. $table->json('seasons')->nullable()->comment('赛季列表 JSON');
  27. // 辅助字段(根据实际业务需要)
  28. $table->boolean('is_active')->default(true)->comment('是否当前活跃联赛');
  29. $table->timestamp('last_synced_at')->nullable()->comment('最后从API同步时间');
  30. $table->timestamps();
  31. });
  32. }
  33. /**
  34. * Reverse the migrations.
  35. */
  36. public function down(): void
  37. {
  38. Schema::dropIfExists('leagues');
  39. }
  40. };