Fix FLEXIAPI-172 Fix drop_aliases_table migration when there is more than one alias

This commit is contained in:
Timothée Jaussoin 2024-05-02 12:57:26 +02:00
parent 4f79ddca2b
commit 905c440fde

View file

@ -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,7 +38,7 @@ return new class extends Migration
->insertUsing(
['account_id','alias', 'domain'],
DB::table('accounts')
->select('id','phone','domain')
->select('id', 'phone', 'domain')
->whereNotNull('phone')
);