resolvemos o problema dos ZEE e ZFI
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-07 19:46:35 +02:00
parent 0a086c3fa5
commit bdd766c68a
74 changed files with 6401 additions and 32 deletions
@@ -0,0 +1,138 @@
<?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
{
$identity = DB::selectOne('select current_database() as database, inet_server_port() as port');
if (! (str_ends_with($identity->database, '_test') && (int) $identity->port === 55441) && ! config('partnerships.installation_authorized')) {
throw new RuntimeException('Use isolated QA, or the authenticated partnership installation with verified backup/restore.');
}
Schema::table('portal_partnerships', function (Blueprint $t) {
$t->foreignUuid('organization_id')->nullable()->constrained('organizations')->restrictOnDelete();
$t->foreignId('sector_id')->nullable()->constrained('sectors')->restrictOnDelete();
$t->unsignedInteger('version')->default(1);
$t->string('kind')->default('seeking');
$t->string('partnership_type')->nullable();
$t->jsonb('payload')->default('{}');
$t->uuid('client_key')->nullable();
$t->date('deadline')->nullable();
$t->timestampTz('published_at')->nullable();
$t->unique(['user_id', 'client_key']);
$t->index(['status', 'sector_id', 'partnership_type']);
});
Schema::create('partnership_origins', function (Blueprint $t) {
$t->id();
$t->foreignId('partnership_id')->constrained('portal_partnerships')->restrictOnDelete();
$t->string('type');
$t->string('target_id');
$t->unique(['partnership_id', 'type', 'target_id']);
$t->index(['type', 'target_id']);
});
Schema::create('partnership_locations', function (Blueprint $t) {
$t->id();
$t->foreignId('partnership_id')->constrained('portal_partnerships')->restrictOnDelete();
$t->foreignUuid('geo_location_id')->constrained('geo_locations')->restrictOnDelete();
$t->string('role');
$t->text('source_reference');
$t->unique(['partnership_id', 'geo_location_id', 'role']);
});
Schema::create('partnership_interests', function (Blueprint $t) {
$t->id();
$t->foreignId('partnership_id')->constrained('portal_partnerships')->restrictOnDelete();
$t->foreignId('user_id')->constrained('users')->restrictOnDelete();
$t->foreignUuid('organization_id')->nullable()->constrained('organizations')->restrictOnDelete();
$t->text('proposal');
$t->string('status')->default('submitted');
$t->unsignedInteger('version')->default(1);
$t->jsonb('payload')->default('{}');
$t->jsonb('assessment')->default('{}');
$t->text('decision_reason')->nullable();
$t->timestampsTz();
$t->unique(['partnership_id', 'user_id']);
});
Schema::create('partnership_rooms', function (Blueprint $t) {
$t->id();
$t->foreignId('interest_id')->unique()->constrained('partnership_interests')->restrictOnDelete();
$t->string('status')->default('negotiation');
$t->unsignedInteger('version')->default(1);
$t->jsonb('agreement')->nullable();
$t->timestampsTz();
});
Schema::create('partnership_messages', function (Blueprint $t) {
$t->id();
$t->foreignId('room_id')->constrained('partnership_rooms')->restrictOnDelete();
$t->foreignId('author_id')->constrained('users')->restrictOnDelete();
$t->uuid('client_key');
$t->text('body');
$t->timestampTz('created_at')->useCurrent();
$t->unique(['room_id', 'author_id', 'client_key']);
});
Schema::create('partnership_documents', function (Blueprint $t) {
$t->id();
$t->foreignId('room_id')->constrained('partnership_rooms')->restrictOnDelete();
$t->foreignUuid('document_id')->constrained('documents')->restrictOnDelete();
$t->foreignId('owner_id')->constrained('users')->restrictOnDelete();
$t->boolean('shared')->default(false);
$t->timestampTz('created_at')->useCurrent();
$t->unique(['room_id', 'document_id']);
});
Schema::create('partnership_milestones', function (Blueprint $t) {
$t->id();
$t->foreignId('room_id')->constrained('partnership_rooms')->restrictOnDelete();
$t->foreignId('responsible_id')->constrained('users')->restrictOnDelete();
$t->string('title');
$t->date('due_date')->nullable();
$t->string('status')->default('pending');
$t->text('evidence')->nullable();
$t->unsignedInteger('version')->default(1);
$t->timestampsTz();
});
Schema::create('partnership_events', function (Blueprint $t) {
$t->uuid('id')->primary();
$t->foreignId('partnership_id')->constrained('portal_partnerships')->restrictOnDelete();
$t->foreignId('actor_id')->constrained('users')->restrictOnDelete();
$t->string('event_type');
$t->unsignedInteger('aggregate_version');
$t->jsonb('payload');
$t->timestampTz('occurred_at')->useCurrent();
});
Schema::create('partnership_notifications', function (Blueprint $t) {
$t->id();
$t->foreignUuid('event_id')->constrained('partnership_events')->restrictOnDelete();
$t->foreignId('user_id')->constrained('users')->restrictOnDelete();
$t->string('title');
$t->string('href');
$t->timestampTz('read_at')->nullable();
$t->unique(['event_id', 'user_id']);
});
}
public function down(): void
{
$identity = DB::selectOne('select current_database() as database, inet_server_port() as port');
if (! (str_ends_with($identity->database, '_test') && (int) $identity->port === 55441)) {
throw new RuntimeException('Rollback is restricted to isolated QA; preserve active records and restore a verified backup instead.');
}
foreach (['partnership_events', 'partnership_interests', 'partnership_origins', 'partnership_locations'] as $table) {
if (DB::table($table)->exists()) {
throw new RuntimeException('Preserve partnership data and history before rollback.');
}
}
foreach (['partnership_notifications', 'partnership_events', 'partnership_milestones', 'partnership_documents', 'partnership_messages', 'partnership_rooms', 'partnership_interests', 'partnership_locations', 'partnership_origins'] as $table) {
Schema::drop($table);
}
Schema::table('portal_partnerships', function (Blueprint $t) {
$t->dropForeign(['organization_id']);
$t->dropForeign(['sector_id']);
$t->dropUnique(['user_id', 'client_key']);
$t->dropIndex(['status', 'sector_id', 'partnership_type']);
$t->dropColumn(['organization_id', 'sector_id', 'version', 'kind', 'partnership_type', 'payload', 'client_key', 'deadline', 'published_at']);
});
}
};
@@ -0,0 +1,90 @@
<?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
{
private function guard(bool $install = false): void
{
$identity = DB::selectOne('select current_database() as database, inet_server_port() as port');
if (! (str_ends_with($identity->database, '_test') && (int) $identity->port === 55441) && ! ($install && config('virtual-desk.installation_authorized'))) {
throw new RuntimeException('Use isolated QA or the authenticated virtual desk installation with verified restore.');
}
}
public function up(): void
{
$this->guard(true);
Schema::create('desk_service_versions', function (Blueprint $t) {
$t->uuid('id')->primary(); $t->string('code'); $t->unsignedInteger('version'); $t->string('status')->default('draft');
$t->jsonb('definition'); $t->jsonb('source'); $t->foreignId('author_id')->constrained('users')->restrictOnDelete();
$t->foreignId('published_by')->nullable()->constrained('users')->restrictOnDelete(); $t->timestampTz('published_at')->nullable(); $t->timestampsTz(); $t->unique(['code', 'version']);
});
Schema::create('desk_cases', function (Blueprint $t) {
$t->uuid('id')->primary(); $t->foreignId('user_id')->constrained('users')->restrictOnDelete();
$t->foreignUuid('organization_id')->nullable()->constrained('organizations')->restrictOnDelete();
$t->foreignUuid('company_id')->nullable()->constrained('investment_company_declarations')->restrictOnDelete();
$t->foreignUuid('submission_id')->nullable()->constrained('investment_submissions')->restrictOnDelete();
$t->uuid('simulation_id')->nullable(); $t->string('title'); $t->uuid('client_key'); $t->unsignedInteger('version')->default(1);
$t->text('payload'); $t->jsonb('workflow'); $t->timestampTz('closed_at')->nullable(); $t->timestampsTz(); $t->unique(['user_id', 'client_key']);
});
Schema::create('desk_requests', function (Blueprint $t) {
$t->uuid('id')->primary(); $t->foreignUuid('case_id')->constrained('desk_cases')->restrictOnDelete();
$t->foreignUuid('service_version_id')->constrained('desk_service_versions')->restrictOnDelete();
$t->foreignId('analyst_id')->nullable()->constrained('users')->restrictOnDelete(); $t->string('status')->default('draft');
$t->unsignedInteger('version')->default(1); $t->uuid('client_key'); $t->text('payload'); $t->string('protocol')->nullable()->unique();
$t->text('submitted_snapshot')->nullable(); $t->jsonb('editable_fields')->nullable(); $t->timestampTz('submitted_at')->nullable();
$t->timestampTz('due_at')->nullable(); $t->timestampTz('closed_at')->nullable(); $t->timestampsTz(); $t->unique(['case_id', 'client_key']);
});
Schema::create('desk_documents', function (Blueprint $t) {
$t->uuid('id')->primary(); $t->foreignUuid('case_id')->constrained('desk_cases')->restrictOnDelete();
$t->foreignUuid('document_id')->constrained('documents')->restrictOnDelete(); $t->foreignUuid('request_id')->nullable()->constrained('desk_requests')->restrictOnDelete();
$t->string('category'); $t->string('stage')->nullable(); $t->date('valid_until')->nullable(); $t->text('source_reference');
$t->foreignId('linked_by')->constrained('users')->restrictOnDelete(); $t->timestampTz('created_at')->useCurrent(); $t->unique(['case_id', 'document_id']);
});
Schema::create('desk_events', function (Blueprint $t) {
$t->uuid('id')->primary(); $t->foreignUuid('case_id')->constrained('desk_cases')->restrictOnDelete();
$t->foreignUuid('request_id')->nullable()->constrained('desk_requests')->restrictOnDelete(); $t->foreignId('actor_id')->constrained('users')->restrictOnDelete();
$t->string('action'); $t->unsignedInteger('version'); $t->text('payload'); $t->timestampTz('created_at')->useCurrent();
});
Schema::create('desk_revisions', function (Blueprint $t) {
$t->id(); $t->foreignUuid('request_id')->constrained('desk_requests')->restrictOnDelete(); $t->unsignedInteger('version');
$t->text('snapshot'); $t->timestampTz('created_at')->useCurrent(); $t->unique(['request_id', 'version']);
});
Schema::create('desk_messages', function (Blueprint $t) {
$t->uuid('id')->primary(); $t->foreignUuid('request_id')->constrained('desk_requests')->restrictOnDelete();
$t->foreignId('actor_id')->constrained('users')->restrictOnDelete(); $t->uuid('client_key'); $t->text('body'); $t->timestampTz('created_at')->useCurrent();
$t->unique(['request_id', 'actor_id', 'client_key']);
});
Schema::create('desk_notifications', function (Blueprint $t) {
$t->id(); $t->foreignUuid('event_id')->constrained('desk_events')->restrictOnDelete(); $t->foreignId('user_id')->constrained('users')->restrictOnDelete();
$t->string('title'); $t->string('href'); $t->timestampTz('read_at')->nullable(); $t->unique(['event_id', 'user_id']);
});
Schema::create('desk_institutional_links', function (Blueprint $t) {
$t->uuid('id')->primary(); $t->string('stage'); $t->string('entity'); $t->string('purpose'); $t->text('url'); $t->string('contact')->nullable();
$t->string('status')->default('pending'); $t->unsignedInteger('version')->default(1); $t->text('source_reference');
$t->timestampTz('verified_at')->nullable(); $t->foreignId('verified_by')->nullable()->constrained('users')->restrictOnDelete(); $t->timestampsTz();
});
Schema::create('desk_payments', function (Blueprint $t) {
$t->uuid('id')->primary(); $t->foreignUuid('request_id')->constrained('desk_requests')->restrictOnDelete();
$t->string('reference')->unique(); $t->decimal('amount', 18, 2); $t->string('currency', 3); $t->text('source_reference');
$t->string('status')->default('pending'); $t->foreignUuid('document_id')->nullable()->constrained('documents')->restrictOnDelete();
$t->foreignId('verified_by')->nullable()->constrained('users')->restrictOnDelete(); $t->text('reason')->nullable(); $t->unsignedInteger('version')->default(1); $t->timestampsTz();
});
DB::statement("ALTER TABLE desk_requests ADD CONSTRAINT desk_request_status CHECK (status IN ('draft','submitted','reviewing','returned','opinion','accepted','rejected','closed','cancelled'))");
DB::statement("ALTER TABLE desk_requests ADD CONSTRAINT desk_request_receipt CHECK (status IN ('draft','cancelled') OR (protocol IS NOT NULL AND submitted_snapshot IS NOT NULL AND submitted_at IS NOT NULL))");
DB::statement('ALTER TABLE desk_payments ADD CONSTRAINT desk_payment_amount CHECK(amount>0)');
}
public function down(): void
{
$this->guard();
foreach (['desk_cases', 'desk_service_versions', 'desk_institutional_links'] as $table) {
if (DB::table($table)->exists()) throw new RuntimeException('Preserve virtual desk data before rollback.');
}
foreach (['desk_payments', 'desk_institutional_links', 'desk_notifications', 'desk_messages', 'desk_revisions', 'desk_events', 'desk_documents', 'desk_requests', 'desk_cases', 'desk_service_versions'] as $table) Schema::drop($table);
}
};