Schema Migrations Table

tommyd456 picture tommyd456 · Sep 30, 2013 · Viewed 25k times · Source

In my Rails 4 app I would like to collapse my migration files into one large file (similar to schema.rb) as it's time to do some housekeeping but I'm not sure on how to access the table in the database that stores migration data so that when I run a migration I don't receive any errors/conflicts.

Question How can I access and delete the data in the table that stores migration data?

Answer

David Lowenfels picture David Lowenfels · Feb 11, 2015

for fun, you can also manipulate these in the console by making a model class for them...

class SchemaMigration < ActiveRecord::Base; self.primary_key = :version; end

then you can do SchemaMigration.all, SchemaMigration.last.delete, etc.

Really just a substitute for using SQL, and it is very rare that you would need to mess around at this low level… generally a bad idea but cool to see how to do it :)