From 3c51d2353b0042fcb8d524ae2032008bf9a8bb2d Mon Sep 17 00:00:00 2001 From: mnv Date: Sat, 26 Sep 2020 23:24:22 +0300 Subject: [PATCH 1/6] #15 fix migration for existing users --- .../add_referral_to_users_table.php | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/database/migrations/add_referral_to_users_table.php b/database/migrations/add_referral_to_users_table.php index e60e34d..0599c31 100755 --- a/database/migrations/add_referral_to_users_table.php +++ b/database/migrations/add_referral_to_users_table.php @@ -11,7 +11,9 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; +use Questocat\Referral\Traits\UserReferral; class AddReferralToUsersTable extends Migration { @@ -20,10 +22,30 @@ class AddReferralToUsersTable extends Migration */ public function up() { - Schema::table('users', function (Blueprint $table) { - $table->string('referred_by')->nullable()->index(); - $table->string('affiliate_id')->unique(); - }); + DB::beginTransaction(); + try { + Schema::table('users', function (Blueprint $table) { + $table->string('referred_by')->nullable()->index(); + $table->string('affiliate_id')->nullable()->unique(); + }); + + /** @var \Illuminate\Database\Eloquent\Collection|UserReferral[] $users */ + $users = config('referral.user_model')::all(); + foreach ($users as $user) { + $user->affiliate_id = $user::generateReferral(); + $user->save(); + } + + Schema::table('users', function (Blueprint $table) { + $table->string('affiliate_id')->nullable(false)->change(); + }); + + DB::commit(); + } + catch (\Throwable $e) { + DB::rollBack(); + throw $e; + } } /** From 3673516a7f7eaf03b68c951ce7df1a06729ef836 Mon Sep 17 00:00:00 2001 From: mnv Date: Sat, 26 Sep 2020 23:30:36 +0300 Subject: [PATCH 2/6] #15 fix migration for existing users --- database/migrations/add_referral_to_users_table.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/database/migrations/add_referral_to_users_table.php b/database/migrations/add_referral_to_users_table.php index 0599c31..2d05852 100755 --- a/database/migrations/add_referral_to_users_table.php +++ b/database/migrations/add_referral_to_users_table.php @@ -41,8 +41,7 @@ public function up() }); DB::commit(); - } - catch (\Throwable $e) { + } catch (\Throwable $e) { DB::rollBack(); throw $e; } From d216592682622bde0bb6a72d5bdd29b9d2aab18a Mon Sep 17 00:00:00 2001 From: mnv Date: Sat, 26 Sep 2020 23:36:01 +0300 Subject: [PATCH 3/6] #15 fix The 'newline_after_open_tag' fixer cannot be enabled again because it has already been enabled --- .styleci.yml | 1 - database/migrations/add_referral_to_users_table.php | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 1fe63de..05c4ba9 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,7 +1,6 @@ preset: symfony enabled: - - newline_after_open_tag - strict - strict_param - ordered_use diff --git a/database/migrations/add_referral_to_users_table.php b/database/migrations/add_referral_to_users_table.php index 2d05852..0599c31 100755 --- a/database/migrations/add_referral_to_users_table.php +++ b/database/migrations/add_referral_to_users_table.php @@ -41,7 +41,8 @@ public function up() }); DB::commit(); - } catch (\Throwable $e) { + } + catch (\Throwable $e) { DB::rollBack(); throw $e; } From 3b44dec53ab66378359855b92f8ada5297898e9a Mon Sep 17 00:00:00 2001 From: mnv Date: Sat, 26 Sep 2020 23:40:44 +0300 Subject: [PATCH 4/6] #15 fix The risky 'strict' fixer cannot be enabled because risky mode is not enabled --- .styleci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.styleci.yml b/.styleci.yml index 05c4ba9..47b26b1 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,6 +1,7 @@ preset: symfony enabled: + - risky - strict - strict_param - ordered_use From 4258aca2af0c374c948e6041bc4e63eb506de6f0 Mon Sep 17 00:00:00 2001 From: mnv Date: Sat, 26 Sep 2020 23:41:40 +0300 Subject: [PATCH 5/6] #15 fix The 'risky' fixer does not exist --- .styleci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 47b26b1..2d534e5 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,7 +1,4 @@ preset: symfony enabled: - - risky - - strict - - strict_param - ordered_use From 424f29e0d0059780afdc63ee26fcaeae1262c0dd Mon Sep 17 00:00:00 2001 From: mnv Date: Sat, 26 Sep 2020 23:43:08 +0300 Subject: [PATCH 6/6] #15 fix code style --- database/migrations/add_referral_to_users_table.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/database/migrations/add_referral_to_users_table.php b/database/migrations/add_referral_to_users_table.php index 0599c31..2d05852 100755 --- a/database/migrations/add_referral_to_users_table.php +++ b/database/migrations/add_referral_to_users_table.php @@ -41,8 +41,7 @@ public function up() }); DB::commit(); - } - catch (\Throwable $e) { + } catch (\Throwable $e) { DB::rollBack(); throw $e; }