|
6 | 6 |
|
7 | 7 | return new class extends Migration |
8 | 8 | { |
| 9 | + /** |
| 10 | + * Get the database connection for the migration. |
| 11 | + */ |
| 12 | + public function getConnection(): ?string |
| 13 | + { |
| 14 | + return config('vantage.database_connection'); |
| 15 | + } |
| 16 | + |
9 | 17 | /** |
10 | 18 | * Run the migrations. |
11 | 19 | * |
12 | 20 | * Performance optimization: Add indexes for common queries |
13 | 21 | */ |
14 | 22 | public function up(): void |
15 | 23 | { |
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) { |
17 | 32 | // Index for filtering by created_at (most common filter) |
18 | 33 | $table->index('created_at', 'idx_vantage_jobs_created_at'); |
19 | 34 |
|
@@ -42,7 +57,14 @@ public function up(): void |
42 | 57 | */ |
43 | 58 | public function down(): void |
44 | 59 | { |
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) { |
46 | 68 | $table->dropIndex('idx_vantage_jobs_created_at'); |
47 | 69 | $table->dropIndex('idx_vantage_jobs_status'); |
48 | 70 | $table->dropIndex('idx_vantage_jobs_created_status'); |
|
0 commit comments