From 905c440fde23b05bb67c117fea6500f3424ded85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Thu, 2 May 2024 12:57:26 +0200 Subject: [PATCH] Fix FLEXIAPI-172 Fix drop_aliases_table migration when there is more than one alias --- .../migrations/2024_04_09_140622_drop_aliases_table.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/flexiapi/database/migrations/2024_04_09_140622_drop_aliases_table.php b/flexiapi/database/migrations/2024_04_09_140622_drop_aliases_table.php index 899636b..6864388 100644 --- a/flexiapi/database/migrations/2024_04_09_140622_drop_aliases_table.php +++ b/flexiapi/database/migrations/2024_04_09_140622_drop_aliases_table.php @@ -5,8 +5,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up() { Schema::table('accounts', function (Blueprint $table) { @@ -14,7 +13,7 @@ return new class extends Migration }); DB::table('accounts')->update([ - 'phone' => DB::raw('(select alias from aliases where aliases.account_id = accounts.id)') + 'phone' => DB::raw('(select alias from (select * from aliases where id in (select min(id) from aliases group by account_id)) as a where a.account_id = accounts.id)') ]); Schema::dropIfExists('aliases'); @@ -39,9 +38,9 @@ return new class extends Migration ->insertUsing( ['account_id','alias', 'domain'], DB::table('accounts') - ->select('id','phone','domain') + ->select('id', 'phone', 'domain') ->whereNotNull('phone') - ); + ); Schema::table('accounts', function (Blueprint $table) { $table->dropColumn('phone');