Generating Schema from Existing Database

by Brian on 12/24/2007

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
end

def 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:

  1. The problem with dynamically typed languages
  2. An Error Caused By Not Missing a Constant
  3. Booting from a CD in Mac OS X when ‘C’ doesn’t work
  4. Default Timeouts in Python urllib2
  5. Finding A Niche
blog comments powered by Disqus

Previous post:

Next post: