2026_11_12_130000_bind_first_deposit_choices.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. if (!Schema::hasColumn('promotion_first_deposit_choices', 'activity_id')) {
  10. Schema::table('promotion_first_deposit_choices', fn (Blueprint $table) => $table->unsignedBigInteger('activity_id')->nullable());
  11. }
  12. if (!Schema::hasColumn('promotion_first_deposit_choices', 'rule_snapshot')) {
  13. Schema::table('promotion_first_deposit_choices', fn (Blueprint $table) => $table->json('rule_snapshot')->nullable());
  14. }
  15. if (!Schema::hasTable('promotion_first_deposit_cutovers')) {
  16. Schema::create('promotion_first_deposit_cutovers', function (Blueprint $table) {
  17. $table->string('source', 32)->primary();
  18. $table->unsignedBigInteger('last_order_id');
  19. });
  20. }
  21. // Keep the original automatic reward for orders already placed at cutover.
  22. $cutovers = array_map(fn (string $source) => [
  23. 'source' => $source,
  24. 'last_order_id' => Schema::hasTable($source) ? (int) DB::table($source)->useWritePdo()->max('id') : 0,
  25. ], ['payment_orders', 'recharges']);
  26. DB::table('promotion_first_deposit_cutovers')->insertOrIgnore($cutovers);
  27. }
  28. public function down(): void
  29. {
  30. Schema::dropIfExists('promotion_first_deposit_cutovers');
  31. Schema::table('promotion_first_deposit_choices', fn (Blueprint $table) => $table->dropColumn(['activity_id', 'rule_snapshot']));
  32. }
  33. };