'connected', 'upstream_mirrors.connection' => 'courier_migration_test', 'database.connections.courier_migration_test' => [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ], ]); DB::purge('courier_migration_test'); Schema::connection('courier_migration_test')->create('js_jst_order_express_details', function (Blueprint $table): void { $table->integer('id'); $table->longText('logistic_id')->nullable(); }); } public function test_migration_and_rollback_preserve_waybills_and_nulls(): void { $table = DB::connection('courier_migration_test')->table('js_jst_order_express_details'); $rows = [['id' => 1, 'logistic_id' => '001234567890123456789'], ['id' => 2, 'logistic_id' => null]]; $table->insert($rows); $migration = require base_path('database/migrations/2026_09_09_160000_index_courier_detail_pagination.php'); $migration->up(); $migration->up(); $this->assertTrue(Schema::connection('courier_migration_test')->hasIndex('js_jst_order_express_details', 'idx_courier_detail_id_waybill')); $this->assertSame($rows, $table->orderBy('id')->get()->map(fn ($row) => (array) $row)->all()); $migration->down(); $this->assertFalse(Schema::connection('courier_migration_test')->hasIndex('js_jst_order_express_details', 'idx_courier_detail_id_waybill')); $this->assertSame($rows, $table->orderBy('id')->get()->map(fn ($row) => (array) $row)->all()); } public function test_oversize_waybill_stops_migration_without_truncation(): void { $value = str_repeat('A', 101); $table = DB::connection('courier_migration_test')->table('js_jst_order_express_details'); $table->insert(['id' => 1, 'logistic_id' => $value]); $migration = require base_path('database/migrations/2026_09_09_160000_index_courier_detail_pagination.php'); try { $migration->up(); $this->fail('Oversize source data must stop migration.'); } catch (RuntimeException $exception) { $this->assertSame($value, $table->value('logistic_id')); $this->assertFalse(Schema::connection('courier_migration_test')->hasIndex('js_jst_order_express_details', 'idx_courier_detail_id_waybill')); } } }