How can I export database structure from the db into migration file?
Asked Answered
C

2

9

Is there a way to export database structure in the database from the rails application? I believe there is a way to export Data from the db using rake.

rake db:migrate will create tables from migration files. Is there a command that does opposite way so that migration files will be generated from the db?

I have previously built a rails application during 3.0.x version.

I have many more migration files than the actual number of tables in the database because I have some migration file which adds and removes or change the column structure of the database.

Obviously, I can manually change each migration file and change it into migration file with 3.1 standard, but I just want to know if there is a way to export data base structure. (Or, deriving from existing schema file)

Chilt answered 18/9, 2011 at 1:43 Comment(0)
A
14

Use command rake db:schema:dump, it will do it for you

Edit: You might be interested in this link: http://www.tutorialspoint.com/ruby-on-rails/rails-and-rake.htm

Acupuncture answered 18/9, 2011 at 1:48 Comment(3)
That worked :P Thanks!, so its my task to split the file into different migration files?Chilt
No. You can "load" the schema directly with rake too. Then you can migrate any changes since you dumped the schema.Prandial
Pavling's right. You'd use rake db:schema:load to load it up.Underglaze
N
-1

After rake db:schema:dump you can use a gem called schema_to_scaffold to generate a scaffold script. it outputs: rails g scaffold users fname:string lname:string bdate:date email:string encrypted_password:string from your schema.rb our your renamed schema.rb. Check here

Nadda answered 6/12, 2012 at 17:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.