@@ -31,7 +31,7 @@ return new class extends Migration
|
||||
$t->dropConstrainedForeignId('primary_territory_id');
|
||||
$t->dropColumn('territory_version');
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ return new class extends Migration
|
||||
]);
|
||||
DB::statement('DROP INDEX IF EXISTS simulation_form_drafts_owner_active_unique');
|
||||
DB::statement('CREATE INDEX simulation_form_drafts_owner_active_idx ON public.simulation_form_drafts(owner_user_id, updated_at DESC) WHERE owner_user_id IS NOT NULL AND deleted_at IS NULL');
|
||||
DB::statement("CREATE UNIQUE INDEX simulation_form_drafts_claimed_token_unique ON public.simulation_form_drafts(claimed_token_hash) WHERE claimed_token_hash IS NOT NULL");
|
||||
DB::statement('CREATE UNIQUE INDEX simulation_form_drafts_claimed_token_unique ON public.simulation_form_drafts(claimed_token_hash) WHERE claimed_token_hash IS NOT NULL');
|
||||
|
||||
Schema::create('simulation_draft_business_links', function ($table): void {
|
||||
$table->uuid('id')->primary();
|
||||
|
||||
@@ -26,7 +26,7 @@ return new class extends Migration
|
||||
DB::statement("ALTER TABLE investment_zones ADD CONSTRAINT investment_zones_physical_category_check CHECK (physical_category IS NULL OR physical_category IN ('economic_zone','industrial_park','industrial_free_zone','integrated_tourism_area','other','unknown'))");
|
||||
DB::statement("ALTER TABLE investment_zones ADD CONSTRAINT investment_zones_legal_regime_check CHECK (legal_regime IS NULL OR legal_regime IN ('zee','zfi','general','pending','not_applicable'))");
|
||||
DB::statement("ALTER TABLE investment_zones ADD CONSTRAINT investment_zones_operational_status_check CHECK (operational_status IN ('operational','implementation','planned','suspended','unknown'))");
|
||||
DB::statement("ALTER TABLE investment_zones ADD CONSTRAINT investment_zones_area_check CHECK (area_value IS NULL OR area_value >= 0)");
|
||||
DB::statement('ALTER TABLE investment_zones ADD CONSTRAINT investment_zones_area_check CHECK (area_value IS NULL OR area_value >= 0)');
|
||||
|
||||
Schema::create('investment_zone_locations', function (Blueprint $table): void {
|
||||
$table->uuid('id')->primary();
|
||||
@@ -65,7 +65,7 @@ return new class extends Migration
|
||||
DB::statement('ALTER TABLE investment_zones DROP CONSTRAINT IF EXISTS investment_zones_area_check, DROP CONSTRAINT IF EXISTS investment_zones_operational_status_check, DROP CONSTRAINT IF EXISTS investment_zones_legal_regime_check, DROP CONSTRAINT IF EXISTS investment_zones_physical_category_check');
|
||||
Schema::table('investment_zones', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('parent_zone_id');
|
||||
$table->dropColumn(['physical_category','legal_regime','operational_status','area_value','area_unit','aliases','activities','resources','historical_territory','data_as_of','sources_consulted_at']);
|
||||
$table->dropColumn(['physical_category', 'legal_regime', 'operational_status', 'area_value', 'area_unit', 'aliases', 'activities', 'resources', 'historical_territory', 'data_as_of', 'sources_consulted_at']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -78,7 +78,7 @@ return new class extends Migration
|
||||
DB::statement("ALTER TABLE portal_resource_links ADD CONSTRAINT portal_resource_links_relationship_check CHECK (relationship IN ('applies_to','supports','version_of','translation_of','amends','repeals','implements','cites','related_to'))");
|
||||
DB::statement("ALTER TABLE portal_resource_links ADD CONSTRAINT portal_resource_links_applicability_check CHECK (applicability IN ('required','conditional','support','optional_template','evidence'))");
|
||||
DB::statement("ALTER TABLE portal_resource_links ADD CONSTRAINT portal_resource_links_basis_check CHECK ((applicability NOT IN ('required','conditional') OR length(trim(coalesce(basis_reference,''))) >= 5) AND (applicability <> 'conditional' OR length(trim(coalesce(condition_text,''))) >= 5))");
|
||||
DB::statement("ALTER TABLE portal_resources ADD CONSTRAINT portal_resources_metadata_version_check CHECK (metadata_version > 0)");
|
||||
DB::statement('ALTER TABLE portal_resources ADD CONSTRAINT portal_resources_metadata_version_check CHECK (metadata_version > 0)');
|
||||
DB::statement("ALTER TABLE portal_resource_revisions ADD CONSTRAINT portal_resource_revisions_change_type_check CHECK (change_type IN ('created','metadata_updated','published','unpublished'))");
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ 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
|
||||
|
||||
@@ -12,7 +12,7 @@ return new class extends Migration
|
||||
Schema::table('portal_resource_links', function (Blueprint $table): void {
|
||||
$table->string('review_status', 16)->default('pending');
|
||||
});
|
||||
DB::statement("ALTER TABLE portal_resource_links DROP CONSTRAINT portal_resource_links_target_type_check");
|
||||
DB::statement('ALTER TABLE portal_resource_links DROP CONSTRAINT portal_resource_links_target_type_check');
|
||||
DB::statement("ALTER TABLE portal_resource_links ADD CONSTRAINT portal_resource_links_target_type_check CHECK (target_type IN ('theme','module','activity','stage','procedure','entity','territory','document','investment_type','legal_source','requirement'))");
|
||||
DB::statement("ALTER TABLE portal_resource_links ADD CONSTRAINT portal_resource_links_review_status_check CHECK (review_status IN ('pending','confirmed'))");
|
||||
DB::statement('ALTER TABLE portal_resource_revisions DROP CONSTRAINT portal_resource_revisions_change_type_check');
|
||||
|
||||
@@ -19,60 +19,128 @@ return new class extends Migration
|
||||
{
|
||||
$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']);
|
||||
$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->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']);
|
||||
$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->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']);
|
||||
$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']);
|
||||
$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();
|
||||
$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']);
|
||||
$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->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']);
|
||||
$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();
|
||||
$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();
|
||||
$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))");
|
||||
@@ -83,8 +151,12 @@ return new class extends Migration
|
||||
{
|
||||
$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.');
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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(): void
|
||||
{
|
||||
$identity = DB::selectOne('select current_database() as database, inet_server_port() as port');
|
||||
if (! (app()->environment('testing') && str_ends_with($identity->database, '_test') && (int) $identity->port === 55441)
|
||||
&& ! config('virtual-desk.installation_authorized')) {
|
||||
throw new RuntimeException('Guidance requires isolated QA or authenticated installation with verified restore.');
|
||||
}
|
||||
}
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
$this->guard();
|
||||
DB::statement('ALTER TABLE desk_events ADD COLUMN event_order bigint GENERATED ALWAYS AS IDENTITY');
|
||||
DB::statement('CREATE UNIQUE INDEX desk_event_order_unique ON desk_events(event_order)');
|
||||
Schema::table('desk_cases', function (Blueprint $t) {
|
||||
$t->foreignUuid('investor_id')->nullable()->constrained('investors')->restrictOnDelete();
|
||||
$t->foreignUuid('project_id')->nullable()->constrained('projects')->restrictOnDelete();
|
||||
$t->foreignUuid('journey_id')->nullable()->constrained('investor_journeys')->restrictOnDelete();
|
||||
$t->foreignId('interest_request_id')->nullable()->constrained('interest_requests')->restrictOnDelete();
|
||||
});
|
||||
Schema::table('tasks', function (Blueprint $t) {
|
||||
$t->foreignUuid('desk_case_id')->nullable()->constrained('desk_cases')->restrictOnDelete();
|
||||
$t->foreignUuid('desk_request_id')->nullable()->constrained('desk_requests')->restrictOnDelete();
|
||||
$t->string('guidance_key', 100)->nullable();
|
||||
$t->foreignId('accepted_by')->nullable()->constrained('users')->restrictOnDelete();
|
||||
$t->timestampTz('accepted_at')->nullable();
|
||||
$t->string('external_sync_status')->nullable();
|
||||
$t->unique(['desk_case_id', 'guidance_key']);
|
||||
});
|
||||
DB::statement("ALTER TABLE tasks ADD CONSTRAINT guidance_task_acceptance CHECK (desk_case_id IS NULL OR (accepted_by IS NOT NULL AND accepted_at IS NOT NULL AND guidance_key IS NOT NULL AND data_classification = 'confidential' AND external_sync_status = 'pending_authorization'))");
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->guard();
|
||||
if (DB::table('tasks')->whereNotNull('desk_case_id')->exists() || DB::table('desk_cases')->whereNotNull('investor_id')->exists()) {
|
||||
throw new RuntimeException('Preserve guidance associations and accepted tasks before rollback.');
|
||||
}
|
||||
DB::statement('ALTER TABLE tasks DROP CONSTRAINT guidance_task_acceptance');
|
||||
DB::statement('ALTER TABLE desk_events DROP COLUMN event_order');
|
||||
Schema::table('tasks', function (Blueprint $t) {
|
||||
$t->dropUnique(['desk_case_id', 'guidance_key']);
|
||||
foreach (['desk_case_id', 'desk_request_id', 'accepted_by'] as $column) {
|
||||
$t->dropConstrainedForeignId($column);
|
||||
}
|
||||
$t->dropColumn(['guidance_key', 'accepted_at', 'external_sync_status']);
|
||||
});
|
||||
Schema::table('desk_cases', function (Blueprint $t) {
|
||||
foreach (['investor_id', 'project_id', 'journey_id', 'interest_request_id'] as $column) {
|
||||
$t->dropConstrainedForeignId($column);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user