1

I have inherited a Ruby on Rails project where the programmer didn't use rake to create the db schema, so it seems very out of synch, is there a way to rectify this?

James Hall
  • 6,469
  • 6
  • 27
  • 28

1 Answers1

2

First create a schema.rb file

rake db:schema:dump

Then make a migration ot of it.

class CreateMigration < ActiveRecord::Migration
  def self.up
    # insert schema.rb here
  end

  def self.down
  end
end

You might also need to create the schema_migrations table, and manually add the timestamp for this migration to it.

Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
Bert Goethals
  • 7,867
  • 2
  • 20
  • 32
  • 1
    You don't need to put the schema in a migration, it will be in `db/schema.rb` and that's good enough, as people can load it using `rake db:schema:load`. – Ryan Bigg Jun 02 '11 at 23:03
  • It just so that the "initial" migration would exist, and one can start a fresh with rake db:migrate as well. – Bert Goethals Jun 02 '11 at 23:18