core updates for seeding and testing
This commit is contained in:
@@ -14,8 +14,5 @@ class AuditTrailDatabaseSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
Model::unguard();
|
|
||||||
|
|
||||||
// $this->call("OthersTableSeeder");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class CountriesDatabaseSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
|
$this->command?->info('Running CountriesDatabaseSeeder');
|
||||||
$this->call([
|
$this->call([
|
||||||
IsoCountriesSeeder::class,
|
IsoCountriesSeeder::class,
|
||||||
IsoCountrySubdivisionsSeeder::class,
|
IsoCountrySubdivisionsSeeder::class,
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ namespace Modules\Helpdesk\Concerns;
|
|||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Modules\Helpdesk\Models\Ticket;
|
use Modules\Helpdesk\Models\Ticket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method hasMany(string $class, string $string)
|
||||||
|
*/
|
||||||
trait HasHelpdeskTickets
|
trait HasHelpdeskTickets
|
||||||
{
|
{
|
||||||
/** @return HasMany<Ticket> */
|
/** @return HasMany<Ticket> */
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Pricing\Database\Seeders;
|
namespace Modules\Pricing\Database\Seeders;
|
||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class PricingDatabaseSeeder extends Seeder
|
final class PricingDatabaseSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Run the database seeds.
|
* Run the database seeds.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run(): void
|
||||||
{
|
{
|
||||||
DB::table('platform_prices')->insert([
|
$plans = [
|
||||||
[
|
[
|
||||||
'code' => 'basic',
|
'code' => 'basic',
|
||||||
'name' => 'Basic',
|
'name' => 'Basic',
|
||||||
@@ -24,12 +24,15 @@ class PricingDatabaseSeeder extends Seeder
|
|||||||
'annual_amount' => 49000,
|
'annual_amount' => 49000,
|
||||||
'currency' => 'gbp',
|
'currency' => 'gbp',
|
||||||
'badge_label' => 'Starter',
|
'badge_label' => 'Starter',
|
||||||
'features' => json_encode(['Warehouse dashboard', 'Inventory overview', 'Basic audit trail', 'Email support']),
|
'features' => [
|
||||||
|
'Warehouse dashboard',
|
||||||
|
'Inventory overview',
|
||||||
|
'Basic audit trail',
|
||||||
|
'Email support',
|
||||||
|
],
|
||||||
'sort_order' => 10,
|
'sort_order' => 10,
|
||||||
'is_featured' => false,
|
'is_featured' => false,
|
||||||
'is_active' => true,
|
'is_active' => true,
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now(),
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'code' => 'advanced',
|
'code' => 'advanced',
|
||||||
@@ -40,12 +43,16 @@ class PricingDatabaseSeeder extends Seeder
|
|||||||
'annual_amount' => 99000,
|
'annual_amount' => 99000,
|
||||||
'currency' => 'gbp',
|
'currency' => 'gbp',
|
||||||
'badge_label' => 'Popular',
|
'badge_label' => 'Popular',
|
||||||
'features' => json_encode(['Everything in Basic', 'Replenishment workflows', 'Reporting workspace', 'M3 integration status', 'Priority support']),
|
'features' => [
|
||||||
|
'Everything in Basic',
|
||||||
|
'Replenishment workflows',
|
||||||
|
'Reporting workspace',
|
||||||
|
'M3 integration status',
|
||||||
|
'Priority support',
|
||||||
|
],
|
||||||
'sort_order' => 20,
|
'sort_order' => 20,
|
||||||
'is_featured' => true,
|
'is_featured' => true,
|
||||||
'is_active' => true,
|
'is_active' => true,
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now(),
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'code' => 'pro',
|
'code' => 'pro',
|
||||||
@@ -56,29 +63,69 @@ class PricingDatabaseSeeder extends Seeder
|
|||||||
'annual_amount' => 199000,
|
'annual_amount' => 199000,
|
||||||
'currency' => 'gbp',
|
'currency' => 'gbp',
|
||||||
'badge_label' => 'Enterprise',
|
'badge_label' => 'Enterprise',
|
||||||
'features' => json_encode(['Everything in Advanced', 'Multi-company administration', 'Security and audit controls', 'Document archive', 'Carrier management', 'Dedicated support']),
|
'features' => [
|
||||||
|
'Everything in Advanced',
|
||||||
|
'Multi-company administration',
|
||||||
|
'Security and audit controls',
|
||||||
|
'Document archive',
|
||||||
|
'Carrier management',
|
||||||
|
'Dedicated support',
|
||||||
|
],
|
||||||
'sort_order' => 30,
|
'sort_order' => 30,
|
||||||
'is_featured' => false,
|
'is_featured' => false,
|
||||||
'is_active' => true,
|
'is_active' => true,
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now(),
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'code' => 'ultimate',
|
'code' => 'ultimate',
|
||||||
'name' => 'Ultimate',
|
'name' => 'Ultimate',
|
||||||
'strapline' => 'Ultimate Enterprise Grade Administration',
|
'strapline' => 'Ultimate Enterprise Grade Administration',
|
||||||
'description' => 'Full platform administration for regulated warehouse,unlimited warehouses and users, carrier and document operations.',
|
'description' => 'Full platform administration for regulated warehouse, unlimited warehouses and users, carrier and document operations.',
|
||||||
'monthly_amount' => 1009900,
|
'monthly_amount' => 1009900,
|
||||||
'annual_amount' => 1000000,
|
'annual_amount' => 1000000,
|
||||||
'currency' => 'gbp',
|
'currency' => 'gbp',
|
||||||
'badge_label' => 'Enterprise',
|
'badge_label' => 'Enterprise',
|
||||||
'features' => json_encode(['Everything in pro', 'Multi-company administration', 'Security and audit controls', 'Document archive', 'Carrier management', 'Dedicated support']),
|
'features' => [
|
||||||
|
'Everything in Pro',
|
||||||
|
'Multi-company administration',
|
||||||
|
'Security and audit controls',
|
||||||
|
'Document archive',
|
||||||
|
'Carrier management',
|
||||||
|
'Dedicated support',
|
||||||
|
],
|
||||||
'sort_order' => 50,
|
'sort_order' => 50,
|
||||||
'is_featured' => false,
|
'is_featured' => false,
|
||||||
'is_active' => true,
|
'is_active' => true,
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now(),
|
|
||||||
],
|
],
|
||||||
]);
|
];
|
||||||
|
|
||||||
|
foreach ($plans as $plan) {
|
||||||
|
$exists = DB::table('platform_prices')
|
||||||
|
->where('code', $plan['code'])
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
$payload = [
|
||||||
|
'name' => $plan['name'],
|
||||||
|
'strapline' => $plan['strapline'],
|
||||||
|
'description' => $plan['description'],
|
||||||
|
'monthly_amount' => $plan['monthly_amount'],
|
||||||
|
'annual_amount' => $plan['annual_amount'],
|
||||||
|
'currency' => $plan['currency'],
|
||||||
|
'badge_label' => $plan['badge_label'],
|
||||||
|
'features' => json_encode($plan['features'], JSON_THROW_ON_ERROR),
|
||||||
|
'sort_order' => $plan['sort_order'],
|
||||||
|
'is_featured' => $plan['is_featured'],
|
||||||
|
'is_active' => $plan['is_active'],
|
||||||
|
'updated_at' => now(),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (! $exists) {
|
||||||
|
$payload['created_at'] = now();
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::table('platform_prices')->updateOrInsert(
|
||||||
|
['code' => $plan['code']],
|
||||||
|
$payload
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,5 +15,6 @@ class DatabaseSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
$this->call(PlatformSeeder::class);
|
$this->call(PlatformSeeder::class);
|
||||||
$this->call(PricingDatabaseSeeder::class);
|
$this->call(PricingDatabaseSeeder::class);
|
||||||
|
$this->call(ModuleDatabaseSeeder::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use mpba\Modules\Facades\Module;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
final class ModuleDatabaseSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Modules intentionally seeded elsewhere or excluded from module auto-seeding.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
private const SKIP_MODULES = [
|
||||||
|
// 'Platform',
|
||||||
|
// 'Pricing',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed all enabled Laravel modules that expose a module database seeder.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
foreach (Module::allEnabled() as $module) {
|
||||||
|
$moduleName = $module->getName();
|
||||||
|
|
||||||
|
if (in_array($moduleName, self::SKIP_MODULES, true)) {
|
||||||
|
$this->command?->warn("Skipping module: {$moduleName} - excluded from automatic module seeding");
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$seederClass = $this->resolveSeederClass($moduleName);
|
||||||
|
|
||||||
|
if ($seederClass === null) {
|
||||||
|
$this->command?->warn("Skipping module: {$moduleName} - no module seeder found");
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->command?->info("Seeding module: {$moduleName}");
|
||||||
|
$this->command?->line("Seeder class: {$seederClass}");
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->call($seederClass);
|
||||||
|
} catch (Throwable $exception) {
|
||||||
|
$this->command?->error("Module seed failed: {$moduleName}");
|
||||||
|
$this->command?->error($exception->getMessage());
|
||||||
|
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->command?->info("Seeded module: {$moduleName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the module database seeder class using supported project patterns.
|
||||||
|
*/
|
||||||
|
private function resolveSeederClass(string $moduleName): ?string
|
||||||
|
{
|
||||||
|
$candidates = [
|
||||||
|
"Modules\\{$moduleName}\\Database\\Seeders\\{$moduleName}DatabaseSeeder",
|
||||||
|
"Modules\\{$moduleName}\\Database\\Seeders\\{$moduleName}Seeder",
|
||||||
|
"Modules\\{$moduleName}\\Database\\Seeders\\DatabaseSeeder",
|
||||||
|
|
||||||
|
// Legacy lowercase namespace variants used by some existing modules.
|
||||||
|
"Modules\\{$moduleName}\\database\\seeders\\{$moduleName}DatabaseSeeder",
|
||||||
|
"Modules\\{$moduleName}\\database\\seeders\\{$moduleName}Seeder",
|
||||||
|
"Modules\\{$moduleName}\\database\\seeders\\DatabaseSeeder",
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($candidates as $candidate) {
|
||||||
|
if (class_exists($candidate)) {
|
||||||
|
return $candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user