Skip to content

Commit db1260e

Browse files
committed
fix: fix migration to handle custom database connections and missing tables
1 parent 5cad475 commit db1260e

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

database/migrations/2025_11_30_000003_add_performance_indexes_to_vantage_jobs.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,29 @@
66

77
return new class extends Migration
88
{
9+
/**
10+
* Get the database connection for the migration.
11+
*/
12+
public function getConnection(): ?string
13+
{
14+
return config('vantage.database_connection');
15+
}
16+
917
/**
1018
* Run the migrations.
1119
*
1220
* Performance optimization: Add indexes for common queries
1321
*/
1422
public function up(): void
1523
{
16-
Schema::table('vantage_jobs', function (Blueprint $table) {
24+
$connection = $this->getConnection();
25+
$schema = Schema::connection($connection);
26+
27+
if (!$schema->hasTable('vantage_jobs')) {
28+
return;
29+
}
30+
31+
$schema->table('vantage_jobs', function (Blueprint $table) {
1732
// Index for filtering by created_at (most common filter)
1833
$table->index('created_at', 'idx_vantage_jobs_created_at');
1934

@@ -42,7 +57,14 @@ public function up(): void
4257
*/
4358
public function down(): void
4459
{
45-
Schema::table('vantage_jobs', function (Blueprint $table) {
60+
$connection = $this->getConnection();
61+
$schema = Schema::connection($connection);
62+
63+
if (!$schema->hasTable('vantage_jobs')) {
64+
return;
65+
}
66+
67+
$schema->table('vantage_jobs', function (Blueprint $table) {
4668
$table->dropIndex('idx_vantage_jobs_created_at');
4769
$table->dropIndex('idx_vantage_jobs_status');
4870
$table->dropIndex('idx_vantage_jobs_created_status');

0 commit comments

Comments
 (0)