Question

I started building my app in PHP but was convinced by some developer friends to change to RoR instead. Since I already had my database structure designed and created in mysql, I never used any rails migrations to create tables; I just created the appropriate models to match the existing database schema.

So, now I am at the point where I want to test deployment and, of course, I have no migrations to rake to recreate the db on, for example, Heroku.

I know that I can simply go back and recreate the database by creating migrations but my app has dozens of tables with hundreds of fields in total.

Is there any way to create a set of migrations based on my existing db schema, or will I just have to knuckle under and build the migrations one by one to recreate the structure via rails' migrations.

Was it helpful?

Solution

Actually, there are some rake tasks to do the work:

rake db:schema:dump     # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load     # Load a schema.rb file into the database

You can run: heroku run rake db:schema:load.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top