2026_10_26_120000_create_maintenance_settings.php 1.7 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Schema;
  6. return new class extends Migration {
  7. public function up(): void
  8. {
  9. Schema::create('maintenance_settings', function (Blueprint $table) {
  10. $table->id(); $table->string('scope_code', 32)->unique(); $table->json('platforms');
  11. $table->boolean('enabled')->default(false)->index(); $table->dateTime('starts_at');
  12. $table->dateTime('ends_at')->nullable(); $table->string('timezone', 64); $table->timestamps();
  13. });
  14. Schema::create('maintenance_translations', function (Blueprint $table) {
  15. $table->id(); $table->unsignedBigInteger('maintenance_id'); $table->string('language', 8); $table->text('content');
  16. $table->unique(['maintenance_id', 'language']);
  17. $table->foreign('maintenance_id')->references('id')->on('maintenance_settings')->onDelete('cascade');
  18. });
  19. // Fixed scopes. Deployment must never start maintenance on its own.
  20. $now = gmdate('Y-m-d H:i:s');
  21. foreach (['site', 'third:1', 'third:2', 'third:3', 'third:4', 'third:5', 'third:6', 'third:7', 'self:sport', 'self:lottery'] as $scope) {
  22. DB::table('maintenance_settings')->insert(['scope_code' => $scope, 'platforms' => '["PC","H5","APP"]',
  23. 'enabled' => false, 'starts_at' => $now, 'ends_at' => null, 'timezone' => 'Asia/Shanghai', 'created_at' => $now, 'updated_at' => $now]);
  24. }
  25. }
  26. public function down(): void { Schema::dropIfExists('maintenance_translations'); Schema::dropIfExists('maintenance_settings'); }
  27. };