Ruby rake db reversing backup

less than 1 minute read

디비 리버싱 백업 http://www.theirishpenguin.com/2009/11/26/generate-rails-migrations-from-your-postgresql-or-mysql-database.html

Create a new empty Rails project called schemer In your config/database.yml file, point at the database you wish to dump to a migrations file Run the command rake db:schema:dump This should create a db/schema.rb file. Amazingly this effectively is your migrations file! To tidy up create a file called file db/migrate/20091125205635_create_initial_schema.rb Then copy the create_table statements from the schema.rb file into the new file 20091125205635_create_initial_schema.rb Here’s a template class CreateInitialSchema < ActiveRecord::Migration

def self.up # Put all create_table statements from schema.rb file here # Note: You don’t need the ‘ActiveRecord::Schema.define(:version’ # line or it’s enclosing end statement # … # … end

def self.down # Don’t really need this end

end Once you’ve all this done you can just run rake db:migrate and you should have a new sqlite db up and running under db/development.sqlite3