Forráskód Böngészése

Merge pull request #4087 from pixelfed/staging

Add migration
daniel 2 éve
szülő
commit
1084bb0ac8

+ 39 - 0
database/migrations/2023_01_15_041933_add_missing_profile_id_to_users_table.php

@@ -0,0 +1,39 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+use App\Profile;
+use App\User;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        User::whereNull('profile_id')
+        ->chunk(20, function($users) {
+            foreach($users as $user) {
+                $profile = Profile::whereUsername($user->username)->first();
+                if($profile) {
+                    $user->profile_id = $profile->id;
+                    $user->save();
+                }
+            }
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+
+    }
+};