This commit is contained in:
Doar Mihai
2026-04-03 20:55:51 +03:00
parent a8a48f3f6f
commit 31e666ef33
7 changed files with 586 additions and 68 deletions
@@ -0,0 +1,60 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('jobs', function (Blueprint $table) {
// Single column indexes for common filters
$table->index('posted_at', 'idx_jobs_posted_at');
$table->index('job_type', 'idx_jobs_type');
$table->index('experience_level', 'idx_jobs_experience');
$table->index('remote_allowed', 'idx_jobs_remote');
$table->index('created_at', 'idx_jobs_created_at');
$table->index('expires_at', 'idx_jobs_expires_at');
// Composite indexes for common query patterns
$table->index(['job_category_id', 'posted_at'], 'idx_jobs_category_posted');
$table->index(['job_type', 'posted_at'], 'idx_jobs_type_posted');
$table->index(['remote_allowed', 'posted_at'], 'idx_jobs_remote_posted');
$table->index(['job_source_id', 'posted_at'], 'idx_jobs_source_posted');
$table->index(['expires_at', 'deleted_at'], 'idx_jobs_expires_deleted');
// Full-text index for search (if not already exists)
DB::statement('ALTER TABLE jobs ADD FULLTEXT idx_jobs_search (title, company, description)');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('jobs', function (Blueprint $table) {
// Drop single column indexes
$table->dropIndex('idx_jobs_posted_at');
$table->dropIndex('idx_jobs_type');
$table->dropIndex('idx_jobs_experience');
$table->dropIndex('idx_jobs_remote');
$table->dropIndex('idx_jobs_created_at');
$table->dropIndex('idx_jobs_expires_at');
// Drop composite indexes
$table->dropIndex('idx_jobs_category_posted');
$table->dropIndex('idx_jobs_type_posted');
$table->dropIndex('idx_jobs_remote_posted');
$table->dropIndex('idx_jobs_source_posted');
$table->dropIndex('idx_jobs_expires_deleted');
// Drop full-text index
DB::statement('ALTER TABLE jobs DROP INDEX idx_jobs_search');
});
}
};