2024_07_14_233110_update_oauth_accounts_status.php 855 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. return new class extends Migration
  4. {
  5. /**
  6. * Run the migrations.
  7. */
  8. public function up(): void
  9. {
  10. DB::table('user_oauth')
  11. ->join('user', 'user_oauth.user_id', '=', 'user.id')
  12. ->where('user.status', 0)
  13. ->whereRaw('ABS(TIMESTAMPDIFF(SECOND, user_oauth.created_at, user.created_at)) <= 5')
  14. ->update(['user.status' => 1]);
  15. }
  16. /**
  17. * Reverse the migrations.
  18. */
  19. public function down(): void
  20. {
  21. DB::table('user_oauth')
  22. ->join('user', 'user_oauth.user_id', '=', 'user.id')
  23. ->where('user.status', 1) // 状态从1
  24. ->whereRaw('ABS(TIMESTAMPDIFF(SECOND, user_oauth.created_at, user.created_at)) <= 5')
  25. ->update(['user.status' => 0]); // 更新为0
  26. }
  27. };