assertFalse(Schema::hasTable('users')); $this->assertFalse(Schema::hasTable('sessions')); $this->assertFalse(Schema::hasTable('password_reset_tokens')); $this->assertFalse(Schema::hasColumn('trackers', 'user_id')); } public function test_down_restores_the_tables_and_column(): void { $this->migration()->down(); $this->assertTrue(Schema::hasTable('users')); $this->assertTrue(Schema::hasTable('sessions')); $this->assertTrue(Schema::hasTable('password_reset_tokens')); $this->assertTrue(Schema::hasColumn('trackers', 'user_id')); } public function test_restored_user_id_is_nullable_so_existing_trackers_survive(): void { DB::table('trackers')->insert([ 'label' => 'Counter', 'unit' => 'units', 'count' => 3, 'created_at' => now(), 'updated_at' => now(), ]); $this->migration()->down(); $nullable = DB::selectOne( 'select is_nullable from information_schema.columns where table_schema = database() and table_name = ? and column_name = ?', ['trackers', 'user_id'] ); $this->assertSame('YES', $nullable->is_nullable ?? $nullable->IS_NULLABLE); } public function test_up_drops_them_again_respecting_foreign_keys(): void { $this->migration()->down(); $this->migration()->up(); $this->assertFalse(Schema::hasTable('users')); $this->assertFalse(Schema::hasColumn('trackers', 'user_id')); } public function test_the_counter_survives_the_round_trip(): void { $trackerId = DB::table('trackers')->insertGetId([ 'label' => 'Counter', 'unit' => 'units', 'count' => 77, 'created_at' => now(), 'updated_at' => now(), ]); $this->migration()->down(); $this->migration()->up(); $this->assertSame(77, (int) DB::table('trackers')->where('id', $trackerId)->value('count')); } }