mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-14 15:37:53 +00:00
fix(#157): migrations and seeders for pgsql
This commit is contained in:
parent
3032c09778
commit
fceacfe4b3
2 changed files with 14 additions and 16 deletions
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Plugin;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
|
|
@ -13,16 +13,16 @@ return new class extends Migration
|
|||
public function up(): void
|
||||
{
|
||||
// Find and handle duplicate (user_id, trmnlp_id) combinations
|
||||
$duplicates = DB::table('plugins')
|
||||
->select('user_id', 'trmnlp_id', DB::raw('COUNT(*) as count'))
|
||||
$duplicates = Plugin::query()
|
||||
->selectRaw('user_id, trmnlp_id, COUNT(*) as duplicate_count')
|
||||
->whereNotNull('trmnlp_id')
|
||||
->groupBy('user_id', 'trmnlp_id')
|
||||
->having('count', '>', 1)
|
||||
->havingRaw('COUNT(*) > ?', [1])
|
||||
->get();
|
||||
|
||||
// For each duplicate combination, keep the first one (by id) and set others to null
|
||||
foreach ($duplicates as $duplicate) {
|
||||
$plugins = DB::table('plugins')
|
||||
$plugins = Plugin::query()
|
||||
->where('user_id', $duplicate->user_id)
|
||||
->where('trmnlp_id', $duplicate->trmnlp_id)
|
||||
->orderBy('id')
|
||||
|
|
@ -37,9 +37,7 @@ return new class extends Migration
|
|||
continue;
|
||||
}
|
||||
|
||||
DB::table('plugins')
|
||||
->where('id', $plugin->id)
|
||||
->update(['trmnlp_id' => null]);
|
||||
$plugin->update(['trmnlp_id' => null]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ class ExampleRecipesSeeder extends Seeder
|
|||
public function run($user_id = 1): void
|
||||
{
|
||||
Plugin::updateOrCreate(
|
||||
['uuid' => '9e46c6cf-358c-4bfe-8998-436b3a207fec'],
|
||||
[
|
||||
'uuid' => '9e46c6cf-358c-4bfe-8998-436b3a207fec',
|
||||
'name' => 'ÖBB Departures',
|
||||
'user_id' => $user_id,
|
||||
'data_payload' => null,
|
||||
|
|
@ -32,8 +32,8 @@ class ExampleRecipesSeeder extends Seeder
|
|||
);
|
||||
|
||||
Plugin::updateOrCreate(
|
||||
['uuid' => '3b046eda-34e9-4232-b935-c33b989a284b'],
|
||||
[
|
||||
'uuid' => '3b046eda-34e9-4232-b935-c33b989a284b',
|
||||
'name' => 'Weather',
|
||||
'user_id' => $user_id,
|
||||
'data_payload' => null,
|
||||
|
|
@ -51,8 +51,8 @@ class ExampleRecipesSeeder extends Seeder
|
|||
);
|
||||
|
||||
Plugin::updateOrCreate(
|
||||
['uuid' => '21464b16-5f5a-4099-a967-f5c915e3da54'],
|
||||
[
|
||||
'uuid' => '21464b16-5f5a-4099-a967-f5c915e3da54',
|
||||
'name' => 'Zen Quotes',
|
||||
'user_id' => $user_id,
|
||||
'data_payload' => null,
|
||||
|
|
@ -70,8 +70,8 @@ class ExampleRecipesSeeder extends Seeder
|
|||
);
|
||||
|
||||
Plugin::updateOrCreate(
|
||||
['uuid' => '8d472959-400f-46ee-afb2-4a9f1cfd521f'],
|
||||
[
|
||||
'uuid' => '8d472959-400f-46ee-afb2-4a9f1cfd521f',
|
||||
'name' => 'This Day in History',
|
||||
'user_id' => $user_id,
|
||||
'data_payload' => null,
|
||||
|
|
@ -89,8 +89,8 @@ class ExampleRecipesSeeder extends Seeder
|
|||
);
|
||||
|
||||
Plugin::updateOrCreate(
|
||||
['uuid' => '4349fdad-a273-450b-aa00-3d32f2de788d'],
|
||||
[
|
||||
'uuid' => '4349fdad-a273-450b-aa00-3d32f2de788d',
|
||||
'name' => 'Home Assistant',
|
||||
'user_id' => $user_id,
|
||||
'data_payload' => null,
|
||||
|
|
@ -108,8 +108,8 @@ class ExampleRecipesSeeder extends Seeder
|
|||
);
|
||||
|
||||
Plugin::updateOrCreate(
|
||||
['uuid' => 'be5f7e1f-3ad8-4d66-93b2-36f7d6dcbd80'],
|
||||
[
|
||||
'uuid' => 'be5f7e1f-3ad8-4d66-93b2-36f7d6dcbd80',
|
||||
'name' => 'Sunrise/Sunset',
|
||||
'user_id' => $user_id,
|
||||
'data_payload' => null,
|
||||
|
|
@ -127,8 +127,8 @@ class ExampleRecipesSeeder extends Seeder
|
|||
);
|
||||
|
||||
Plugin::updateOrCreate(
|
||||
['uuid' => '82d3ee14-d578-4969-bda5-2bbf825435fe'],
|
||||
[
|
||||
'uuid' => '82d3ee14-d578-4969-bda5-2bbf825435fe',
|
||||
'name' => 'Pollen Forecast',
|
||||
'user_id' => $user_id,
|
||||
'data_payload' => null,
|
||||
|
|
@ -146,8 +146,8 @@ class ExampleRecipesSeeder extends Seeder
|
|||
);
|
||||
|
||||
Plugin::updateOrCreate(
|
||||
['uuid' => '1d98bca4-837d-4b01-b1a1-e3b6e56eca90'],
|
||||
[
|
||||
'uuid' => '1d98bca4-837d-4b01-b1a1-e3b6e56eca90',
|
||||
'name' => 'Holidays (iCal)',
|
||||
'user_id' => $user_id,
|
||||
'data_payload' => null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue