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 committed 2025-12-21 20:58:10 +05:00
1 parent 749208ac97
commit a5bc322170
4 files changed
+92 -7

No files matched your search

+15 -6
View File
@@ -21,11 +21,15 @@
use Database\Seeders\Migrators\CardOrdersMigrator; use Database\Seeders\Migrators\CardOrdersMigrator;
use Database\Seeders\Migrators\VisaMasterSettingsMigrator; use Database\Seeders\Migrators\VisaMasterSettingsMigrator;
use Database\Seeders\Migrators\CardPinOrdersMigrator; use Database\Seeders\Migrators\CardPinOrdersMigrator;
use Database\Seeders\Migrators\ModelHasRolesMigrator;
use Database\Seeders\Migrators\OnlinePaymentsMigrator;
class MigrationController extends Controller class MigrationController extends Controller
{ {
public function index() public function index()
{ {
return $this->test();
$migrators = [ $migrators = [
new ActionEventsMigrator(), new ActionEventsMigrator(),
new UsersMigrator(), new UsersMigrator(),
@@ -42,13 +46,11 @@ public function index()
new CardOrdersMigrator(), new CardOrdersMigrator(),
new CardPinOrdersMigrator(), new CardPinOrdersMigrator(),
new LoanOrdersMigrator(), new LoanOrdersMigrator(),
new VisaMasterSettingsMigrator(), new ModelHasRolesMigrator(),
new MediaMigrator(),
new ProvincesMigrator(),
new VisaMasterPaymentOrdersMigrator(), new VisaMasterPaymentOrdersMigrator(),
new OnlinePaymentsMigrator(),
new MediaMigrator(),
]; ];
foreach ($migrators as $migrator) { foreach ($migrators as $migrator) {
@@ -57,4 +59,11 @@ public function index()
return 'done'; return 'done';
} }
public function test()
{
(new OnlinePaymentsMigrator())->migrate();
return 'done';
}
} }
@@ -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');");
}
}
@@ -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');");
}
}
+8 -1
View File
@@ -13,7 +13,7 @@ public function run(): void
{ {
app()[PermissionRegistrar::class]->forgetCachedPermissions(); app()[PermissionRegistrar::class]->forgetCachedPermissions();
$rolesWithPermissions = '[{"name":"super_admin","guard_name":"web","permissions":["ViewAny:Role","View:Role","Create:Role","Update:Role","Delete:Role","Restore:Role","ForceDelete:Role","ForceDeleteAny:Role","RestoreAny:Role","Replicate:Role","Reorder:Role"]}]'; $rolesWithPermissions = '[{"id":2,"name":"super_admin","guard_name":"web","permissions":["ViewAny:Role","View:Role","Create:Role","Update:Role","Delete:Role","Restore:Role","ForceDelete:Role","ForceDeleteAny:Role","RestoreAny:Role","Replicate:Role","Reorder:Role"]}]';
$directPermissions = '[]'; $directPermissions = '[]';
static::makeRolesWithPermissions($rolesWithPermissions); static::makeRolesWithPermissions($rolesWithPermissions);
@@ -32,26 +32,32 @@ public function run(): void
$additionalRoles = collect([ $additionalRoles = collect([
[ [
'id' => 3,
'name' => 'admin', 'name' => 'admin',
'guard_name' => 'web', 'guard_name' => 'web',
], ],
[ [
'id' => 4,
'name' => 'operator', 'name' => 'operator',
'guard_name' => 'web', 'guard_name' => 'web',
], ],
[ [
'id' => 10,
'name' => 'operator_card', 'name' => 'operator_card',
'guard_name' => 'web', 'guard_name' => 'web',
], ],
[ [
'id' => 11,
'name' => 'operator_loan', 'name' => 'operator_loan',
'guard_name' => 'web', 'guard_name' => 'web',
], ],
[ [
'id' => 12,
'name' => 'client', 'name' => 'client',
'guard_name' => 'web', 'guard_name' => 'web',
], ],
[ [
'id' => 6,
'name' => 'currency_maintainer', 'name' => 'currency_maintainer',
'guard_name' => 'web', 'guard_name' => 'web',
], ],
@@ -74,6 +80,7 @@ protected static function makeRolesWithPermissions(string $rolesWithPermissions)
foreach ($rolePlusPermissions as $rolePlusPermission) { foreach ($rolePlusPermissions as $rolePlusPermission) {
$role = $roleModel::firstOrCreate([ $role = $roleModel::firstOrCreate([
'id' => $rolePlusPermission['id'],
'name' => $rolePlusPermission['name'], 'name' => $rolePlusPermission['name'],
'guard_name' => $rolePlusPermission['guard_name'], 'guard_name' => $rolePlusPermission['guard_name'],
]); ]);