varias alteracoes

This commit is contained in:
2026-09-29 08:41:57 +02:00
parent b77714b156
commit 2e0217b486
51 changed files with 2605 additions and 270 deletions
@@ -0,0 +1,37 @@
<?php
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
{
public function up(): void
{
foreach (['opportunities', 'projects', 'economic_clusters', 'development_corridors', 'investment_zones'] as $table) {
Schema::table($table, function (Blueprint $t) {
$t->foreignUuid('primary_territory_id')->nullable()->constrained('geo_locations')->restrictOnDelete();
$t->unsignedInteger('territory_version')->default(0);
});
}
}
public function down(): void
{
$tables = ['opportunities', 'projects', 'economic_clusters', 'development_corridors', 'investment_zones'];
foreach ($tables as $table) {
if (Schema::hasColumn($table, 'primary_territory_id') && DB::table($table)->whereNotNull('primary_territory_id')->exists()) {
throw new RuntimeException('Preserve territorial assignments before rollback.');
}
}
foreach ($tables as $table) {
if (Schema::hasColumn($table, 'primary_territory_id')) {
Schema::table($table, function (Blueprint $t) {
$t->dropConstrainedForeignId('primary_territory_id');
$t->dropColumn('territory_version');
});
}
}
}
};