runMigrationAgainstLegacySets(); $this->assertSame( [2, 7], DB::table('sets')->orderBy('sort_order')->pluck('id')->all(), ); $this->assertSame( [1, 2], DB::table('sets') ->orderBy('sort_order') ->pluck('sort_order') ->all(), ); $this->expectException(QueryException::class); DB::table('sets')->insert([ 'id' => 9, 'name' => 'Unordered Set', 'description' => 'A set without an explicit position', 'icon_image_url' => '/assets/unordered.png', ]); } public function testRollbackRemovesOrderWithoutDeletingSets(): void { $migration = $this->runMigrationAgainstLegacySets(); $migration->down(); $this->assertFalse(Schema::hasColumn('sets', 'sort_order')); $this->assertSame( [2, 7], DB::table('sets')->orderBy('id')->pluck('id')->all(), ); } private function runMigrationAgainstLegacySets(): object { if (Schema::hasColumn('sets', 'sort_order')) { Schema::table('sets', function (Blueprint $table): void { $table->dropColumn('sort_order'); }); } DB::table('sets')->delete(); DB::table('sets')->insert([ [ 'id' => 7, 'name' => 'Later Set', 'description' => 'Created later', 'icon_image_url' => '/assets/later.png', ], [ 'id' => 2, 'name' => 'Earlier Set', 'description' => 'Created earlier', 'icon_image_url' => '/assets/earlier.png', ], ]); $migration = require database_path(self::MIGRATION_PATH); $migration->up(); return $migration; } }