@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
use WithoutModelEvents;
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
if (! app()->environment(['local', 'testing'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->call(InvestMozReferenceSeeder::class);
|
||||
$this->call(InvestmentReferenceSeeder::class);
|
||||
|
||||
// User::factory(10)->create();
|
||||
|
||||
User::firstOrCreate(
|
||||
['email' => 'test@example.com'],
|
||||
[
|
||||
'name' => 'Test User',
|
||||
'password' => Hash::make(Str::random(48)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Investor;
|
||||
use App\Models\Project;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class InvestMozReferenceSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
if (! app()->environment(['local', 'testing'])) {
|
||||
throw new \RuntimeException('Reference fixtures are restricted to local/testing.');
|
||||
}
|
||||
|
||||
Project::withTrashed()->updateOrCreate(
|
||||
['source_system' => 'example', 'external_id' => 'PROJECT-001'],
|
||||
[
|
||||
'code' => 'EXAMPLE-PROJECT-001',
|
||||
'name' => 'Projecto fictício para validação técnica',
|
||||
'status' => 'draft',
|
||||
'budget_amount' => '1000.00',
|
||||
'budget_currency' => 'MZN',
|
||||
'data_classification' => 'internal',
|
||||
'deleted_at' => null,
|
||||
],
|
||||
);
|
||||
Investor::withTrashed()->updateOrCreate(
|
||||
['source_system' => 'example', 'external_id' => 'INVESTOR-001'],
|
||||
[
|
||||
'legal_name' => 'Entidade fictícia para validação técnica',
|
||||
'investor_type' => 'institutional',
|
||||
'status' => 'prospect',
|
||||
'data_classification' => 'internal',
|
||||
'deleted_at' => null,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\DevelopmentCorridor;
|
||||
use App\Models\EconomicCluster;
|
||||
use App\Models\InvestmentDossier;
|
||||
use App\Models\Project;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class InvestmentPortfolioSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$data = json_decode(File::get(database_path('data/investment-portfolio.json')), true, 512, JSON_THROW_ON_ERROR);
|
||||
DB::transaction(function () use ($data) {
|
||||
DB::select('select pg_advisory_xact_lock(250925, 130000)');
|
||||
$ids = [];
|
||||
foreach (['projects' => [Project::class, 'project_id', 'draft', '6.1 / 6.6'],
|
||||
'clusters' => [EconomicCluster::class, 'cluster_id', 'planned', '4.5.2'],
|
||||
'corridors' => [DevelopmentCorridor::class, 'corridor_id', 'proposed', '4.3.4']] as $kind => [$model, $foreign, $status, $section]) {
|
||||
foreach ($data[$kind] as $item) {
|
||||
// Never overwrite a manually edited record or silently take over its code.
|
||||
$record = $model::withTrashed()->where('code', $item['code'])->first();
|
||||
if ($record && ($record->getAttribute('source_system') !== 'upgrade-v4' || $record->trashed())) {
|
||||
throw new \RuntimeException('Portfolio code collision: '.$item['code']);
|
||||
}
|
||||
$record ??= $model::create(['code' => $item['code'], 'name' => $item['name'], 'status' => $status,
|
||||
'source_system' => 'upgrade-v4', 'external_id' => $item['code'],
|
||||
...($kind === 'clusters' ? ['sector' => $item['name']] : ['description' => $item['description'] ?? $item['focus']])]);
|
||||
$ids[$item['code']] = $record->id;
|
||||
InvestmentDossier::withTrashed()->firstOrCreate([$foreign => $record->id], [
|
||||
'title' => $item['name'], 'source' => $data['source'].' — '.$section,
|
||||
'content' => [...$item, 'notice' => $data['notice']], 'publication_status' => 'draft',
|
||||
]);
|
||||
}
|
||||
}
|
||||
foreach (['clusters' => ['cluster_projects', 'cluster_id'], 'corridors' => ['corridor_projects', 'corridor_id']] as $kind => [$table, $foreign]) {
|
||||
foreach ($data[$kind] as $item) {
|
||||
preg_match_all('/\bA\d{2}\b/', $item['anchors'], $matches);
|
||||
foreach (array_unique($matches[0]) as $code) {
|
||||
$key = [$foreign => $ids[$item['code']], 'project_id' => $ids[$code]];
|
||||
if (! DB::table($table)->where($key)->exists()) {
|
||||
DB::table($table)->insert([...$key, 'id' => (string) Str::uuid(), 'source_system' => 'upgrade-v4',
|
||||
...($kind === 'clusters' ? ['role' => 'anchor'] : [])]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Only unambiguous correspondences in section 4.3.4; no inferred mining anchors.
|
||||
$matrix = ['COR-01' => [1, 2, 3, 4, 6], 'COR-02' => [1, 2, 3, 5], 'COR-03' => [1, 2, 3, 6],
|
||||
'COR-04' => [1, 3], 'COR-05' => [4, 7], 'COR-06' => [2, 3, 7]];
|
||||
foreach ($matrix as $corridor => $clusters) {
|
||||
foreach ($clusters as $cluster) {
|
||||
$key = ['corridor_id' => $ids[$corridor], 'cluster_id' => $ids[sprintf('CLU-%02d', $cluster)]];
|
||||
if (! DB::table('corridor_clusters')->where($key)->exists()) {
|
||||
DB::table('corridor_clusters')->insert([...$key, 'id' => (string) Str::uuid(), 'source_system' => 'upgrade-v4']);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class InvestmentReferenceSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$groups = json_decode(File::get(database_path('data/investment-reference-options.json')), true, 512, JSON_THROW_ON_ERROR);
|
||||
DB::transaction(function () use ($groups) {
|
||||
foreach ($groups as $group => $options) {
|
||||
foreach ([...$options, 'other' => 'Outro — especificar'] as $code => $label) {
|
||||
DB::table('investment_reference_options')->insertOrIgnore(['group' => $group, 'code' => $code, 'label' => $label,
|
||||
'active' => true, 'requires_description' => $code === 'other', 'created_at' => now(), 'updated_at' => now()]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\Sector;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class OpportunitySeeder extends Seeder
|
||||
{
|
||||
/** @var array<int, string> */
|
||||
private array $maturityLabels = [
|
||||
1 => 'Ideia identificada',
|
||||
2 => 'Pré-estudo disponível',
|
||||
3 => 'Estudo de viabilidade em curso',
|
||||
4 => 'Projecto estruturado',
|
||||
5 => 'Pronto para investimento',
|
||||
6 => 'Em negociação ou implementação',
|
||||
];
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$items = [
|
||||
['sector' => 'agronegocio', 'reference' => 'INV-MZ-AGR-001', 'title' => 'Unidade de processamento agrícola em Nampula', 'province' => 'Nampula', 'maturity' => 4, 'amount' => 2500000, 'financing' => 'Capital e parceria técnica', 'impact' => '120 empregos directos e substituição de importações.', 'featured' => true],
|
||||
['sector' => 'energia', 'reference' => 'INV-MZ-ENE-002', 'title' => 'Mini-rede solar para polo produtivo', 'province' => 'Zambézia', 'maturity' => 3, 'amount' => 1200000, 'financing' => 'PPP ou financiamento misto', 'impact' => 'Acesso a energia para 40 unidades produtivas.', 'featured' => true],
|
||||
['sector' => 'turismo', 'reference' => 'INV-MZ-TUR-003', 'title' => 'Eco-lodge costeiro com integração comunitária', 'province' => 'Inhambane', 'maturity' => 2, 'amount' => 1800000, 'financing' => 'Capital privado ou joint venture', 'impact' => 'Emprego local e conservação da faixa costeira.', 'featured' => true],
|
||||
['sector' => 'infraestruturas', 'reference' => 'INV-MZ-INF-004', 'title' => 'Centro logístico provincial', 'province' => 'Sofala', 'maturity' => 4, 'amount' => 8500000, 'financing' => 'Concessão ou PPP', 'impact' => 'Redução de custos logísticos regionais.', 'featured' => false],
|
||||
['sector' => 'economia-azul', 'reference' => 'INV-MZ-BLUE-005', 'title' => 'Processamento de pescado e cadeia fria', 'province' => 'Zambézia', 'maturity' => 2, 'amount' => 900000, 'financing' => 'Capital, crédito ou parceria operacional', 'impact' => 'Redução de perdas pós-captura na pesca artesanal.', 'featured' => false],
|
||||
['sector' => 'mercado-financeiro', 'reference' => 'INV-MZ-FIN-006', 'title' => 'Plataforma de crédito para PME agrícolas', 'province' => 'Maputo Cidade', 'maturity' => 3, 'amount' => 3000000, 'financing' => 'Fundo de investimento ou parceiro financeiro', 'impact' => 'Acesso a financiamento para 300+ pequenas empresas.', 'featured' => false],
|
||||
];
|
||||
|
||||
foreach ($items as $item) {
|
||||
$sector = Sector::where('slug', $item['sector'])->first();
|
||||
if (! $sector) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Opportunity::updateOrCreate(
|
||||
['reference' => $item['reference']],
|
||||
[
|
||||
'sector_id' => $sector->id,
|
||||
'title' => $item['title'],
|
||||
'slug' => Str::slug($item['reference'].'-'.$item['title']),
|
||||
'summary' => $item['impact'],
|
||||
'description' => $item['impact'],
|
||||
'province' => $item['province'],
|
||||
'promoter_name' => 'Promotor em validação',
|
||||
'promoter_type' => 'privado',
|
||||
'maturity_level' => $item['maturity'],
|
||||
'maturity_label' => $this->maturityLabels[$item['maturity']],
|
||||
'estimated_investment_amount' => $item['amount'],
|
||||
'estimated_investment_currency' => 'USD',
|
||||
'financing_modality' => $item['financing'],
|
||||
'expected_impact' => $item['impact'],
|
||||
'status' => 'published',
|
||||
'is_featured' => $item['featured'],
|
||||
'published_at' => now(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Sector;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class SectorSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$sectors = [
|
||||
['name' => 'Agronegócio', 'slug' => 'agronegocio', 'short_description' => 'Produção, agroprocessamento, irrigação e cadeias de valor agrícolas.'],
|
||||
['name' => 'Energia e Mineração', 'slug' => 'energia', 'short_description' => 'Energias renováveis, transição energética e mineração responsável.'],
|
||||
['name' => 'Turismo', 'slug' => 'turismo', 'short_description' => 'Hotelaria, turismo costeiro, cultural e ecológico.'],
|
||||
['name' => 'Infraestruturas', 'slug' => 'infraestruturas', 'short_description' => 'Logística, transportes, parques industriais e energia.'],
|
||||
['name' => 'Economia Azul', 'slug' => 'economia-azul', 'short_description' => 'Pesca, aquacultura, portos e logística marítima.'],
|
||||
['name' => 'Mercado Financeiro', 'slug' => 'mercado-financeiro', 'short_description' => 'Fintech, capital de risco e instrumentos financeiros.'],
|
||||
];
|
||||
|
||||
foreach ($sectors as $index => $sector) {
|
||||
Sector::updateOrCreate(
|
||||
['slug' => $sector['slug']],
|
||||
[...$sector, 'is_active' => true, 'sort_order' => $index + 1, 'published_at' => now()]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user