46 lines
2.7 KiB
PHP
46 lines
2.7 KiB
PHP
<?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
|
|
{
|
|
Schema::table('candidate_submissions', fn (Blueprint $table) => $table->unique(['tenant_id', 'people_process_id', 'id'], 'candidate_submission_process_identity'));
|
|
Schema::table('people_applications', fn (Blueprint $table) => $table->unique(['tenant_id', 'people_process_id', 'id'], 'people_application_process_identity'));
|
|
Schema::create('candidate_triage', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->unsignedBigInteger('tenant_id');
|
|
$table->unsignedBigInteger('people_process_id');
|
|
$table->unsignedBigInteger('candidate_submission_id')->unique();
|
|
$table->unsignedBigInteger('people_application_id')->nullable()->unique();
|
|
$table->foreign(['tenant_id', 'people_process_id', 'candidate_submission_id'], 'triage_submission_scope')->references(['tenant_id', 'people_process_id', 'id'])->on('candidate_submissions')->restrictOnDelete();
|
|
$table->foreign(['tenant_id', 'people_process_id', 'people_application_id'], 'triage_application_scope')->references(['tenant_id', 'people_process_id', 'id'])->on('people_applications')->restrictOnDelete();
|
|
$table->foreignId('created_by')->constrained('users')->restrictOnDelete();
|
|
$table->uuid('operation_key');
|
|
$table->string('input_hash', 64);
|
|
$table->string('outcome', 30);
|
|
$table->unsignedInteger('profile_version');
|
|
$table->text('reason');
|
|
$table->text('public_message');
|
|
$table->timestamp('created_at');
|
|
$table->unique(['tenant_id', 'operation_key']);
|
|
});
|
|
if (DB::getDriverName() === 'sqlite') {
|
|
DB::unprepared("CREATE TRIGGER preserve_candidate_triage_update BEFORE UPDATE ON candidate_triage BEGIN SELECT RAISE(ABORT, 'Preservar decisao de triagem'); END;
|
|
CREATE TRIGGER preserve_candidate_triage_delete BEFORE DELETE ON candidate_triage BEGIN SELECT RAISE(ABORT, 'Preservar decisao de triagem'); END;");
|
|
} elseif (DB::getDriverName() === 'pgsql') {
|
|
DB::unprepared("CREATE FUNCTION sgc_preserve_candidate_triage() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'Preservar decisao de triagem'; END $$;
|
|
CREATE TRIGGER preserve_candidate_triage BEFORE UPDATE OR DELETE ON candidate_triage FOR EACH ROW EXECUTE FUNCTION sgc_preserve_candidate_triage();");
|
|
}
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
throw new LogicException('Preservar decisões e origens das candidaturas.');
|
|
}
|
|
};
|