If you’re porting an existing application to Rails, or building an application in Rails where the database schema already exists, here is a useful command to know:
rake db:schema:dump
This command will create a schema.rb in the db directory which you can then use to build your first migration. For example, copy the contents schema.rb into the file below:
class CreateMigration < ActiveRecord::Migration
def self.up
# Insert schema.rb here
enddef self.down
# I would say it's better not to define this, don't want to accidentally delete your existing data
end
end
Related posts: