varias alteracoes
This commit is contained in:
@@ -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');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user