How should I remove sample data in the self.down method(s) for both the migrations listed below
class FooSampleData < ActiveRecord:Migration
def self.up
Foo.create(:bar => 1)
Foo.create(:bar => 2)
Foo.create(:bar => 3)
end
def self.down
end
end
class FooSampleDataV2 < ActiveRecord:Migration
def self.up
Foo.create(:bar => 4)
Foo.create(:bar => 5)
Foo.create(:bar => 6)
end
def self.down
end
end
If you are creating your database table at the same time, then destroying table will destroy data.
If :bar is unique, you may find by bar and destroy the object.
Edited
I don’t know your scenario. Seed usually is used for starting up an application. If you are in an incremental development (with deploys) usually initial data is included when we create our model, and not in a exclusive migration as you show in your example.
If you really need to do it in a exclusive migration, your drop work will be proportional do your create work.
In my projects I avoid adding data in migrations.
Some useful links: