Enhance MigrationController and ShieldSeeder for improved data migration and role management

- Added new migrators: ModelHasRolesMigrator and OnlinePaymentsMigrator to MigrationController.
- Introduced a test method in MigrationController to facilitate online payments migration.
- Updated ShieldSeeder to include role IDs for better role management and added new roles with specific IDs.
This commit is contained in:
Mekan1206
2025-12-21 20:58:10 +05:00
parent 749208ac97
commit a5bc322170
4 changed files with 92 additions and 7 deletions

View File

@@ -0,0 +1,26 @@
<?php
namespace Database\Seeders\Migrators;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
class ModelHasRolesMigrator
{
public function migrate(): void
{
DB::table('model_has_roles')->truncate();
$path = database_path('data/tested/model_has_roles.json');
$rawData = File::json($path);
foreach ($rawData as $data) {
DB::table('model_has_roles')
->insert($data);
}
DB::statement("SELECT setval('model_has_roles_id_seq', (SELECT MAX(id) from model_has_roles));");
DB::statement("SELECT nextval('model_has_roles_id_seq');");
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Database\Seeders\Migrators;
use App\Modules\CardOrder\Models\CardOrder;
use App\Modules\CardPinOrder\Models\CardPinOrder;
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
class OnlinePaymentsMigrator
{
public function migrate(): void
{
DB::table('online_payments')->truncate();
$path = database_path('data/tested/online_payment_histories.json');
$rawData = File::json($path);
foreach ($rawData as $data) {
if ($data['online_paymantable_type']) {
if ($data['online_paymantable_type'] == 'App\Models\Order\Card\Requisite\CardRequisite') {
continue;
}
$data['online_paymantable_type'] = match ($data['online_paymantable_type']) {
'App\Models\Order\Card\CardOrder' => CardOrder::class,
'App\Models\Order\Card\CardPin\CardPin' => CardPinOrder::class,
// 'App\Modules\SberPaymentOrder\Models\SberPaymentOrder' => SberPaymentOrder::class,
'App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder' => VisaMasterPaymentOrder::class,
'\App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder' => VisaMasterPaymentOrder::class,
};
}
DB::table('online_payments')
->insert($data);
}
DB::statement("SELECT setval('online_payments_id_seq', (SELECT MAX(id) from online_payments));");
DB::statement("SELECT nextval('online_payments_id_seq');");
}
}