File manager - Edit - /var/www/html/homologBancodetalentos/tests/Feature/TalentBank/LegacyMigrationImporterTest.php
Back
<?php namespace Tests\Feature\TalentBank; use App\Support\TalentBank\LegacyMigrationImporter; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Tests\TestCase; /** * Testa o LegacyMigrationImporter com dois bancos SQLite in-memory: * - 'legacy' → banco legado sintético (dados de teste controlados) * - 'testing' → banco alvo (schema mínimo criado aqui) * * Valida comportamentos de importação, idempotência e tratamento de dados inválidos * sem tocar no banco MySQL de desenvolvimento. */ class LegacyMigrationImporterTest extends TestCase { private const LEGACY = 'sqlite_legacy'; private const TARGET = 'sqlite_target'; protected function setUp(): void { parent::setUp(); // Configura ambas as conexões como SQLite :memory: totalmente isoladas config([ 'database.connections.' . self::LEGACY => [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', 'foreign_key_constraints' => false, ], 'database.connections.' . self::TARGET => [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', 'foreign_key_constraints' => false, ], ]); // Garante que o Laravel cria novas conexões PDO (não reutiliza cache) DB::purge(self::LEGACY); DB::purge(self::TARGET); $this->buildLegacySchema(); $this->buildTargetSchema(); $this->seedTargetLookups(); } protected function tearDown(): void { // SQLite :memory: é destruído automaticamente ao fechar a conexão PDO DB::purge(self::LEGACY); DB::purge(self::TARGET); parent::tearDown(); } // ───────────────────────────────────────────────────────────────────────── // Candidatos // ───────────────────────────────────────────────────────────────────────── /** @test */ public function importa_candidato_simples(): void { $this->insertLegacyCandidate([ 'id' => 1, 'cpf' => '12345678909', 'name' => 'João Silva', 'email' => 'joao@example.com', 'active' => 1, 'gender_id' => 1, ]); $report = $this->makeImporter()->importCandidates(); $this->assertSame(1, $report['stats']['candidates']['inserted']); $this->assertCount(0, $report['stats']['candidates']['errors'], $this->firstError($report, 'candidates')); $row = DB::connection(self::TARGET)->table('candidates')->where('cpf', '12345678909')->first(); $this->assertNotNull($row); $this->assertSame('João Silva', $row->name); $this->assertSame('joao@example.com', $row->email); } /** @test */ public function importa_candidato_com_cpf_bigint_sem_zero_a_esquerda(): void { // CPF armazenado como bigint perde o zero inicial no dump $this->insertLegacyCandidate([ 'id' => 2, 'cpf' => 1234567890, // sem zero inicial 'name' => 'Maria Santos', 'email' => 'maria@example.com', ]); $report = $this->makeImporter()->importCandidates(); $this->assertSame(1, $report['stats']['candidates']['inserted']); $row = DB::connection(self::TARGET)->table('candidates')->first(); $this->assertSame('01234567890', $row->cpf, 'CPF deve ser repadejado com zero à esquerda'); } /** @test */ public function importacao_de_candidatos_e_idempotente(): void { $this->insertLegacyCandidate(['id' => 1, 'cpf' => '12345678909', 'name' => 'João', 'email' => 'j@e.com']); $importer = $this->makeImporter(); $importer->importCandidates(); $report = $importer->importCandidates(); $this->assertCount(0, $report['stats']['candidates']['errors'], $this->firstError($report, 'candidates')); $count = DB::connection(self::TARGET)->table('candidates')->count(); $this->assertSame(1, $count, 'Não deve duplicar candidato em re-execução'); } /** @test */ public function candidato_com_cpf_duplicado_no_legado_nao_duplica_no_alvo(): void { // Dois registros com mesmo CPF no legado (dado inconsistente do legado) $this->insertLegacyCandidate(['id' => 1, 'cpf' => '12345678909', 'name' => 'Versão 1', 'email' => 'a@a.com']); $this->insertLegacyCandidate(['id' => 2, 'cpf' => '12345678909', 'name' => 'Versão 2', 'email' => 'b@b.com']); $this->makeImporter()->importCandidates(); $count = DB::connection(self::TARGET)->table('candidates')->count(); $this->assertSame(1, $count, 'CPF duplicado no legado deve resultar em 1 registro no alvo'); } /** @test */ public function candidato_com_neighbourhood_id_invalido_e_importado_com_null(): void { $this->insertLegacyCandidate([ 'id' => 1, 'cpf' => '12345678909', 'name' => 'Ana', 'email' => 'ana@example.com', 'neighbourhood_id' => 9999, // não existe no alvo ]); $report = $this->makeImporter()->importCandidates(); $this->assertSame(1, $report['stats']['candidates']['inserted']); $this->assertCount(0, $report['stats']['candidates']['errors'], $this->firstError($report, 'candidates')); $row = DB::connection(self::TARGET)->table('candidates')->first(); $this->assertNull($row->neighbourhood_id, 'neighbourhood_id inválido deve virar NULL, não causar erro'); } /** @test */ public function candidato_com_occupation_id_invalido_e_importado_com_null(): void { $this->insertLegacyCandidate([ 'id' => 1, 'cpf' => '12345678909', 'name' => 'Carlos', 'email' => 'carlos@example.com', 'occupation_id' => 99999, // não existe ]); $report = $this->makeImporter()->importCandidates(); $this->assertSame(1, $report['stats']['candidates']['inserted']); $row = DB::connection(self::TARGET)->table('candidates')->first(); $this->assertNull($row->occupation_id); } /** @test */ public function candidato_com_ethnicity_string_legada_e_resolvido_para_fk(): void { $this->insertLegacyCandidate([ 'id' => 1, 'cpf' => '12345678909', 'name' => 'Pedro', 'email' => 'pedro@example.com', 'ethnicity' => 'Parda', ]); $this->makeImporter()->importCandidates(); $row = DB::connection(self::TARGET)->table('candidates')->first(); $ethnicityId = DB::connection(self::TARGET)->table('ethnicities')->where('name', 'Parda')->value('id'); $this->assertSame((int) $ethnicityId, (int) $row->ethnicity_id, 'ethnicity string deve ser resolvida para o ID correto'); } /** @test */ public function candidato_com_ethnicity_string_desconhecida_fica_com_null(): void { $this->insertLegacyCandidate([ 'id' => 1, 'cpf' => '12345678909', 'name' => 'Rui', 'email' => 'rui@example.com', 'ethnicity' => 'Extraterrestre', // não existe ]); $this->makeImporter()->importCandidates(); $row = DB::connection(self::TARGET)->table('candidates')->first(); $this->assertNull($row->ethnicity_id); } /** @test */ public function salario_muito_alto_e_limitado_ao_maximo_do_decimal_12_2(): void { $this->insertLegacyCandidate([ 'id' => 1, 'cpf' => '12345678909', 'name' => 'Magnata', 'email' => 'm@example.com', 'desired_payment' => 99999999999.99, // acima do limite ]); $this->makeImporter()->importCandidates(); $row = DB::connection(self::TARGET)->table('candidates')->first(); $this->assertLessThanOrEqual(9999999999.99, (float) $row->desired_payment); } /** @test */ public function telefone_zero_do_legado_vira_null(): void { $this->insertLegacyCandidate([ 'id' => 1, 'cpf' => '12345678909', 'name' => 'Silêncio', 'email' => 's@example.com', 'telephone' => 0, 'cellphone' => 0, ]); $this->makeImporter()->importCandidates(); $row = DB::connection(self::TARGET)->table('candidates')->first(); $this->assertNull($row->telephone); $this->assertNull($row->cellphone); } // ───────────────────────────────────────────────────────────────────────── // Empresas // ───────────────────────────────────────────────────────────────────────── /** @test */ public function importa_empresa_simples(): void { $this->insertLegacyCompany([ 'id' => 1, 'cnpj' => 12345678000195, 'corporate_name' => 'Empresa Teste LTDA', 'email' => 'empresa@teste.com', 'active' => 1, ]); $report = $this->makeImporter()->importCompanies(); $this->assertSame(1, $report['stats']['companies']['inserted']); $this->assertCount(0, $report['stats']['companies']['errors'], $this->firstError($report, 'companies')); $row = DB::connection(self::TARGET)->table('companies')->first(); $this->assertSame('12345678000195', $row->cnpj); $this->assertSame('Empresa Teste LTDA', $row->corporate_name); } /** @test */ public function importacao_de_empresas_e_idempotente(): void { $this->insertLegacyCompany(['id' => 1, 'cnpj' => 12345678000195, 'corporate_name' => 'X', 'email' => 'x@x.com']); $importer = $this->makeImporter(); $importer->importCompanies(); $report = $importer->importCompanies(); $this->assertCount(0, $report['stats']['companies']['errors'], $this->firstError($report, 'companies')); $this->assertSame(1, DB::connection(self::TARGET)->table('companies')->count()); } /** @test */ public function empresa_com_campos_legados_e_mapeada_corretamente(): void { $this->insertLegacyCompany([ 'id' => 1, 'cnpj' => 12345678000195, 'corporate_name' => 'Empresa LTDA', 'occupation_area' => 'Tecnologia', 'county' => 'Angra dos Reis', 'cnae' => '6201501', 'module_id' => 'abc-123', 'module_name' => 'Banco de Talentos', 'email' => 'e@e.com', ]); $this->makeImporter()->importCompanies(); $row = DB::connection(self::TARGET)->table('companies')->first(); $this->assertSame('Tecnologia', $row->occupation_area); $this->assertSame('Angra dos Reis', $row->county); $this->assertSame('6201501', $row->cnae); $this->assertSame('abc-123', $row->module_id); $this->assertSame('Banco de Talentos', $row->module_name); } // ───────────────────────────────────────────────────────────────────────── // Vagas // ───────────────────────────────────────────────────────────────────────── /** @test */ public function importa_vaga_vinculada_a_empresa_existente(): void { $this->insertLegacyCompany(['id' => 1, 'cnpj' => 12345678000195, 'corporate_name' => 'Empresa', 'email' => 'e@e.com']); $this->insertLegacyJob([ 'id' => 10, 'company_id' => 1, 'occupation_id' => 1, 'salary_range_id' => 1, 'contract_type_id' => 1, 'spots_total' => 2, 'descripton' => 'Vaga de teste', ]); // Primeiro migra empresas para criar o vínculo $importer = $this->makeImporter(); $importer->importCompanies(); $report = $importer->importJobs(); $this->assertSame(1, $report['stats']['job_listings']['inserted']); $this->assertCount(0, $report['stats']['job_listings']['errors'], $this->firstError($report, 'job_listings')); $row = DB::connection(self::TARGET)->table('job_listings')->first(); $this->assertSame(10, (int) $row->legacy_id); $this->assertSame('Vaga de teste', $row->description); } /** @test */ public function vaga_sem_empresa_correspondente_e_ignorada(): void { // Vaga sem empresa no legado — company_id = 999 não existe $this->insertLegacyJob([ 'id' => 10, 'company_id' => 999, 'occupation_id' => 1, 'salary_range_id' => 1, 'contract_type_id' => 1, 'spots_total' => 1, 'descripton' => 'Vaga órfã', ]); $report = $this->makeImporter()->importJobs(); $this->assertSame(0, $report['stats']['job_listings']['inserted']); $this->assertSame(1, $report['stats']['job_listings']['skipped']); } /** @test */ public function importacao_de_vagas_e_idempotente(): void { $this->insertLegacyCompany(['id' => 1, 'cnpj' => 12345678000195, 'corporate_name' => 'Empresa', 'email' => 'e@e.com']); $this->insertLegacyJob([ 'id' => 10, 'company_id' => 1, 'occupation_id' => 1, 'salary_range_id' => 1, 'contract_type_id' => 1, 'spots_total' => 1, 'descripton' => 'Vaga', ]); $importer = $this->makeImporter(); $importer->importCompanies(); $importer->importJobs(); $report = $importer->importJobs(); $this->assertCount(0, $report['stats']['job_listings']['errors'], $this->firstError($report, 'job_listings')); $this->assertSame(1, DB::connection(self::TARGET)->table('job_listings')->count()); } // ───────────────────────────────────────────────────────────────────────── // Candidaturas // ───────────────────────────────────────────────────────────────────────── /** @test */ public function importa_candidatura_vinculando_candidato_e_vaga(): void { $this->insertLegacyCompany(['id' => 1, 'cnpj' => 12345678000195, 'corporate_name' => 'Empresa', 'email' => 'e@e.com']); $this->insertLegacyCandidate(['id' => 1, 'cpf' => '12345678909', 'name' => 'João', 'email' => 'j@e.com']); $this->insertLegacyJob([ 'id' => 10, 'company_id' => 1, 'occupation_id' => 1, 'salary_range_id' => 1, 'contract_type_id' => 1, 'spots_total' => 1, 'descripton' => 'Vaga', ]); DB::connection(self::LEGACY)->table('job_applications')->insert([ 'id' => 1, 'candidate_id' => 1, 'job_id' => 10, ]); $importer = $this->makeImporter(); $importer->importCompanies(); $importer->importCandidates(); $importer->importJobs(); $report = $importer->importApplications(); $this->assertSame(1, $report['stats']['job_applications']['inserted']); $this->assertCount(0, $report['stats']['job_applications']['errors'], $this->firstError($report, 'job_applications')); $this->assertSame(1, DB::connection(self::TARGET)->table('job_listing_candidate')->count()); } /** @test */ public function candidatura_duplicada_nao_e_reinserida(): void { $this->insertLegacyCompany(['id' => 1, 'cnpj' => 12345678000195, 'corporate_name' => 'E', 'email' => 'e@e.com']); $this->insertLegacyCandidate(['id' => 1, 'cpf' => '12345678909', 'name' => 'J', 'email' => 'j@e.com']); $this->insertLegacyJob([ 'id' => 10, 'company_id' => 1, 'occupation_id' => 1, 'salary_range_id' => 1, 'contract_type_id' => 1, 'spots_total' => 1, 'descripton' => 'V', ]); DB::connection(self::LEGACY)->table('job_applications')->insert(['id' => 1, 'candidate_id' => 1, 'job_id' => 10]); DB::connection(self::LEGACY)->table('job_applications')->insert(['id' => 2, 'candidate_id' => 1, 'job_id' => 10]); $importer = $this->makeImporter(); $importer->importCompanies(); $importer->importCandidates(); $importer->importJobs(); $importer->importApplications(); $this->assertSame(1, DB::connection(self::TARGET)->table('job_listing_candidate')->count()); } /** @test */ public function import_all_retorna_stats_de_todos_os_dominios(): void { $this->insertLegacyCandidate(['id' => 1, 'cpf' => '12345678909', 'name' => 'A', 'email' => 'a@e.com']); $this->insertLegacyCompany(['id' => 1, 'cnpj' => 12345678000195, 'corporate_name' => 'B', 'email' => 'b@e.com']); $report = $this->makeImporter()->importAll(); $this->assertArrayHasKey('candidates', $report['stats']); $this->assertArrayHasKey('companies', $report['stats']); $this->assertArrayHasKey('job_listings', $report['stats']); $this->assertArrayHasKey('job_applications', $report['stats']); } // ───────────────────────────────────────────────────────────────────────── // Callback de progresso // ───────────────────────────────────────────────────────────────────────── /** @test */ public function progress_callback_e_invocado_durante_importacao(): void { $this->insertLegacyCandidate(['id' => 1, 'cpf' => '12345678909', 'name' => 'A', 'email' => 'a@a.com']); $this->insertLegacyCandidate(['id' => 2, 'cpf' => '98765432100', 'name' => 'B', 'email' => 'b@b.com']); $calls = []; $importer = $this->makeImporter(); $importer->setProgressCallback(function () use (&$calls): void { $calls[] = func_get_args(); }); $importer->importCandidates(); $this->assertNotEmpty($calls, 'O callback deve ter sido chamado pelo menos uma vez'); $this->assertSame('candidates', $calls[0][0], 'Primeiro argumento é o domínio'); } // ───────────────────────────────────────────────────────────────────────── // Infra de suporte ao teste // ───────────────────────────────────────────────────────────────────────── private function makeImporter(): LegacyMigrationImporter { return new LegacyMigrationImporter( legacyConnection: self::LEGACY, targetConnection: self::TARGET, tables: [ 'candidates' => 'candidates', 'companies' => 'companies', 'jobs' => 'jobs', 'job_applications' => 'job_applications', ], batchSize: 100, ); } private function firstError(array $report, string $domain): string { $err = $report['stats'][$domain]['errors'][0] ?? null; return $err ? ($err['message'] ?? json_encode($err)) : ''; } private function insertLegacyCandidate(array $data): void { DB::connection(self::LEGACY)->table('candidates')->insert(array_merge([ 'cpf' => null, 'name' => '', 'email' => null, 'address' => null, 'zip_code' => null, 'birth_date' => null, 'special_needs' => 0, 'telephone' => null, 'cellphone' => null, 'min_payment' => null, 'desired_payment' => null, 'cv_summary' => null, 'has_experience' => null, 'active' => 1, 'neighbourhood_id' => null, 'gender_id' => null, 'marital_status_id' => null, 'occupation_id' => null, 'ethnicity' => null, 'created_at' => now()->toDateTimeString(), 'updated_at' => now()->toDateTimeString(), ], $data)); } private function insertLegacyCompany(array $data): void { DB::connection(self::LEGACY)->table('companies')->insert(array_merge([ 'cnpj' => null, 'corporate_name' => null, 'trading_name' => null, 'occupation_area' => null, 'county' => null, 'cnae' => null, 'logo' => null, 'description' => null, 'address' => null, 'zip_code' => null, 'neighbourhood_id' => null, 'telephone' => null, 'cellphone' => null, 'contact_name' => null, 'email' => null, 'module_id' => null, 'module_name' => null, 'active' => 1, 'created_at' => now()->toDateTimeString(), 'updated_at' => now()->toDateTimeString(), ], $data)); } private function insertLegacyJob(array $data): void { DB::connection(self::LEGACY)->table('jobs')->insert(array_merge([ 'company_id' => null, 'occupation_id' => null, 'salary_range_id' => null, 'contract_type_id' => null, 'neighbourhood_id' => null, 'expertise_level_id' => null, 'modality_id' => null, 'workload_id' => null, 'spots_total' => 1, 'spots_filled' => 0, 'descripton' => '', 'description' => null, 'requirements_mandatory' => null, 'requirements_optional' => null, 'benefits' => null, 'misc_info' => null, 'hide_company' => 0, 'is_hiring' => 1, 'created_at' => now()->toDateTimeString(), 'updated_at' => now()->toDateTimeString(), ], $data)); } // ───────────────────────────────────────────────────────────────────────── // Schema builders // ───────────────────────────────────────────────────────────────────────── private function buildLegacySchema(): void { $con = self::LEGACY; Schema::connection($con)->create('candidates', function (Blueprint $t) { $t->id(); $t->string('cpf')->nullable(); $t->string('name')->nullable(); $t->string('email')->nullable(); $t->string('address')->nullable(); $t->string('zip_code')->nullable(); $t->date('birth_date')->nullable(); $t->tinyInteger('special_needs')->default(0); $t->bigInteger('telephone')->nullable(); $t->bigInteger('cellphone')->nullable(); $t->decimal('min_payment', 8, 2)->nullable(); $t->decimal('desired_payment', 8, 2)->nullable(); $t->text('cv_summary')->nullable(); $t->tinyInteger('has_experience')->nullable(); $t->tinyInteger('active')->nullable(); $t->unsignedBigInteger('neighbourhood_id')->nullable(); $t->unsignedBigInteger('gender_id')->nullable(); $t->unsignedBigInteger('marital_status_id')->nullable(); $t->unsignedBigInteger('occupation_id')->nullable(); $t->string('ethnicity')->nullable(); // string no legado original $t->timestamps(); }); Schema::connection($con)->create('companies', function (Blueprint $t) { $t->id(); $t->bigInteger('cnpj')->nullable(); $t->string('corporate_name')->nullable(); $t->string('trading_name')->nullable(); $t->string('occupation_area')->nullable(); $t->string('county')->nullable(); $t->string('cnae')->nullable(); $t->string('logo')->nullable(); $t->text('description')->nullable(); $t->string('address')->nullable(); $t->string('zip_code')->nullable(); $t->unsignedBigInteger('neighbourhood_id')->nullable(); $t->bigInteger('telephone')->nullable(); $t->bigInteger('cellphone')->nullable(); $t->string('contact_name')->nullable(); $t->string('email')->nullable(); $t->char('module_id', 36)->nullable(); $t->string('module_name')->nullable(); $t->tinyInteger('active')->nullable(); $t->timestamps(); }); Schema::connection($con)->create('jobs', function (Blueprint $t) { $t->id(); $t->unsignedBigInteger('company_id')->nullable(); $t->unsignedBigInteger('occupation_id')->nullable(); $t->unsignedBigInteger('salary_range_id')->nullable(); $t->unsignedBigInteger('contract_type_id')->nullable(); $t->unsignedBigInteger('neighbourhood_id')->nullable(); $t->unsignedBigInteger('expertise_level_id')->nullable(); $t->unsignedBigInteger('modality_id')->nullable(); $t->unsignedBigInteger('workload_id')->nullable(); $t->integer('spots_total')->default(0); $t->integer('spots_filled')->nullable(); $t->text('descripton')->nullable(); // typo do legado $t->text('description')->nullable(); $t->text('requirements_mandatory')->nullable(); $t->text('requirements_optional')->nullable(); $t->text('benefits')->nullable(); $t->text('misc_info')->nullable(); $t->tinyInteger('hide_company')->default(0); $t->tinyInteger('is_hiring')->default(1); $t->timestamps(); }); Schema::connection($con)->create('job_applications', function (Blueprint $t) { $t->id(); $t->unsignedBigInteger('candidate_id')->nullable(); $t->unsignedBigInteger('job_id')->nullable(); // sem timestamps — igual ao legado real }); } private function buildTargetSchema(): void { $con = self::TARGET; Schema::connection($con)->disableForeignKeyConstraints(); // Tabelas de lookup Schema::connection($con)->create('neighbourhoods', fn (Blueprint $t) => $t->id()->unsignedBigInteger('id')); Schema::connection($con)->create('genders', fn (Blueprint $t) => $t->id()); Schema::connection($con)->create('marital_statuses', fn (Blueprint $t) => $t->id()); Schema::connection($con)->create('occupations', fn (Blueprint $t) => $t->id()); Schema::connection($con)->create('ethnicities', function (Blueprint $t) { $t->id(); $t->string('name'); }); Schema::connection($con)->create('salary_ranges', fn (Blueprint $t) => $t->id()); Schema::connection($con)->create('contract_types', fn (Blueprint $t) => $t->id()); Schema::connection($con)->create('expertise_levels', fn (Blueprint $t) => $t->id()); Schema::connection($con)->create('modalities', fn (Blueprint $t) => $t->id()); Schema::connection($con)->create('workloads', fn (Blueprint $t) => $t->id()); Schema::connection($con)->create('companies', function (Blueprint $t) { $t->id(); $t->string('cnpj', 14)->unique(); $t->string('corporate_name')->nullable(); $t->string('trading_name')->nullable(); $t->string('occupation_area')->nullable(); $t->string('county')->nullable(); $t->string('cnae')->nullable(); $t->string('logo')->nullable(); $t->text('description')->nullable(); $t->string('address')->nullable(); $t->string('zip_code')->nullable(); $t->unsignedBigInteger('neighbourhood_id')->nullable(); $t->string('telephone')->nullable(); $t->string('cellphone')->nullable(); $t->string('contact_name')->nullable(); $t->string('email')->nullable(); $t->char('module_id', 36)->nullable(); $t->string('module_name')->nullable(); $t->boolean('email_notifications_enabled')->default(false); $t->boolean('active')->default(true); $t->timestamp('last_login_at')->nullable(); $t->timestamps(); }); Schema::connection($con)->create('candidates', function (Blueprint $t) { $t->id(); $t->string('cpf', 11)->unique(); $t->string('name'); $t->string('email'); $t->text('address')->nullable(); $t->string('zip_code')->nullable(); $t->date('birth_date')->nullable(); $t->boolean('special_needs')->default(false); $t->string('telephone')->nullable(); $t->string('cellphone')->nullable(); $t->decimal('min_payment', 12, 2)->nullable(); $t->decimal('desired_payment', 12, 2)->nullable(); $t->text('cv_summary')->nullable(); $t->boolean('has_experience')->nullable(); $t->boolean('active')->default(true); $t->unsignedBigInteger('neighbourhood_id')->nullable(); $t->unsignedBigInteger('gender_id')->nullable(); $t->unsignedBigInteger('marital_status_id')->nullable(); $t->unsignedBigInteger('occupation_id')->nullable(); $t->unsignedBigInteger('ethnicity_id')->nullable(); $t->timestamps(); }); Schema::connection($con)->create('job_listings', function (Blueprint $t) { $t->id(); $t->unsignedBigInteger('legacy_id')->nullable()->index(); $t->unsignedBigInteger('company_id'); $t->unsignedBigInteger('occupation_id'); $t->unsignedBigInteger('salary_range_id'); $t->unsignedBigInteger('contract_type_id'); $t->unsignedBigInteger('neighbourhood_id')->nullable(); $t->unsignedBigInteger('expertise_level_id')->nullable(); $t->unsignedBigInteger('modality_id')->nullable(); $t->unsignedBigInteger('workload_id')->nullable(); $t->unsignedInteger('spots_total')->default(0); $t->unsignedInteger('spots_filled')->default(0); $t->text('description'); $t->text('requirements_mandatory')->nullable(); $t->text('requirements_optional')->nullable(); $t->text('benefits')->nullable(); $t->text('misc_info')->nullable(); $t->boolean('hide_company')->default(false); $t->boolean('is_hiring')->default(true); $t->timestamps(); }); Schema::connection($con)->create('job_listing_candidate', function (Blueprint $t) { $t->id(); $t->unsignedBigInteger('job_listing_id'); $t->unsignedBigInteger('candidate_id'); $t->string('status')->nullable(); $t->timestamps(); $t->unique(['job_listing_id', 'candidate_id']); }); Schema::connection($con)->enableForeignKeyConstraints(); } private function seedTargetLookups(): void { $con = self::TARGET; DB::connection($con)->table('neighbourhoods')->insert([['id' => 1], ['id' => 2]]); DB::connection($con)->table('genders')->insert([['id' => 1], ['id' => 2], ['id' => 3]]); DB::connection($con)->table('marital_statuses')->insert(array_map(fn ($i) => ['id' => $i], range(1, 5))); DB::connection($con)->table('occupations')->insert(array_map(fn ($i) => ['id' => $i], range(1, 10))); DB::connection($con)->table('ethnicities')->insert([ ['id' => 1, 'name' => 'Branca'], ['id' => 2, 'name' => 'Preta'], ['id' => 3, 'name' => 'Parda'], ['id' => 4, 'name' => 'Amarela'], ['id' => 5, 'name' => 'Indígena'], ['id' => 6, 'name' => 'Não declarado'], ]); DB::connection($con)->table('salary_ranges')->insert(array_map(fn ($i) => ['id' => $i], range(1, 7))); DB::connection($con)->table('contract_types')->insert([['id' => 1], ['id' => 2]]); DB::connection($con)->table('expertise_levels')->insert(array_map(fn ($i) => ['id' => $i], range(1, 5))); DB::connection($con)->table('modalities')->insert(array_map(fn ($i) => ['id' => $i], range(1, 4))); DB::connection($con)->table('workloads')->insert(array_map(fn ($i) => ['id' => $i], range(1, 6))); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings