<commit_before><?php

use Illuminate\Database\Migrations\Migration;

class MigrateClubStaffRelation extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $clubUsers = DB::table('users')->whereNotNull('club_id')->get();
        foreach ($clubUsers as $user) {
            if (!$user->nid) {
                continue;
            }
            DB::table('club_student')->updateOrInsert([
                'student_nid' => $user->nid,
            ], [
                'club_id' => $user->club_id,
            ]);
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $clubStudents = DB::table('club_student')->get();
        foreach ($clubStudents as $clubStudent) {
            DB::table('users')->where(['nid' => $clubStudent->student_nid])<commit_msg>Ignore invalid relation (e.g. User with no Student)<commit_after><?php

use Illuminate\Database\Migrations\Migration;

class MigrateClubStaffRelation extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $clubUsers = DB::table('users')->whereNotNull('club_id')->get();
        foreach ($clubUsers as $user) {
            if (!$user->nid) {
                continue;
            }
            try {
                DB::table('club_student')->updateOrInsert([
                    'student_nid' => $user->nid,
                ], [
                    'club_id' => $user->club_id,
                ]);
            } catch (Exception $ignored) {
                //
            }
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $clubStudents = DB::table('club_student')->get();
        foreach ($clubStudents as $clubStudent) {
            DB::table('users')->where(['nid' => $clubStudent->student_nid])
{'fraction_non_alphanumeric': 0.14964249233912155, 'fraction_numerical': 0.0, 'mean_word_length': 1.6725784447476126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4265025', 'n_tokens_mistral': 567, 'n_tokens_neox': 558, 'n_words': 100}