2026_11_09_120000_extend_maintenance_scope_code.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Support\Facades\DB;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends Migration {
  6. public function up(): void
  7. {
  8. if (!Schema::hasTable('maintenance_settings')) return;
  9. $table = Schema::getConnection()->getTablePrefix() . 'maintenance_settings';
  10. $driver = Schema::getConnection()->getDriverName();
  11. if ($driver === 'mysql') {
  12. DB::statement("ALTER TABLE `{$table}` MODIFY `scope_code` VARCHAR(64) NOT NULL");
  13. } elseif ($driver === 'pgsql') {
  14. DB::statement("ALTER TABLE \"{$table}\" ALTER COLUMN scope_code TYPE VARCHAR(64)");
  15. }
  16. }
  17. public function down(): void
  18. {
  19. if (!Schema::hasTable('maintenance_settings')) return;
  20. // The old admin only recognizes site and category scopes. The FK removes child translations.
  21. DB::table('maintenance_settings')
  22. ->where('scope_code', 'like', 'third:%:%')
  23. ->orWhere('scope_code', 'like', 'self:lottery:%')
  24. ->orWhere('scope_code', 'like', 'self:sport:%')
  25. ->delete();
  26. $table = Schema::getConnection()->getTablePrefix() . 'maintenance_settings';
  27. $driver = Schema::getConnection()->getDriverName();
  28. if ($driver === 'mysql') {
  29. DB::statement("ALTER TABLE `{$table}` MODIFY `scope_code` VARCHAR(32) NOT NULL");
  30. } elseif ($driver === 'pgsql') {
  31. DB::statement("ALTER TABLE \"{$table}\" ALTER COLUMN scope_code TYPE VARCHAR(32)");
  32. }
  33. }
  34. };