Is it possible to do Reverse Engineering in rails migrations?

4 views
Skip to first unread message

sathishkumar sadhasivam

unread,
Nov 11, 2009, 6:56:32 AM11/11/09
to Ruby on Rails: Talk
Hi All,

This is my first post as in joined just now and have some doubts,

I need a to discuss about Rails migrations in detail,

I have a doubt on doing reverse engineering concept in migrations on
existing database.

Consider, I have deleted all the migration files from the folder
RAILS_ROOT/db/migrate/*.

We have all the tables present in Mysql database. Now, I want to
create a migration files for all existing tables.

Is that possible to create those? If yes, how is it?

Even I have deleted the schema.rb file from RAILS_ROOT/db/ folder.

Looking for solution to try it out.

Thanks in Advance to all the user who is going put their thought
process into it,

-Sathish Kumar

Frederick Cheung

unread,
Nov 11, 2009, 8:53:26 AM11/11/09
to Ruby on Rails: Talk

On Nov 11, 11:56 am, sathishkumar sadhasivam
<srssathishku...@gmail.com> wrote:

>
> We have all the tables present in Mysql database. Now, I want to
> create a migration files for all existing tables.
>
> Is that possible to create those? If yes, how is it?
>
> Even I have deleted the schema.rb file from RAILS_ROOT/db/ folder.
>

if you want to recreate the schema.rb file, rake db:schema:dump does
that.

Fred

Marnen Laibow-Koser

unread,
Nov 11, 2009, 9:17:10 AM11/11/09
to rubyonra...@googlegroups.com
Sathish Kumar wrote:
[...]

> Consider, I have deleted all the migration files from the folder
> RAILS_ROOT/db/migrate/*.
>
> We have all the tables present in Mysql database. Now, I want to
> create a migration files for all existing tables.
>
> Is that possible to create those? If yes, how is it?
>
> Even I have deleted the schema.rb file from RAILS_ROOT/db/ folder.

Just check out the migrations and schema.rb again from your version
control repository, same as you would for any accidentally deleted file.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org


--
Posted via http://www.ruby-forum.com/.

Norm Scherer

unread,
Nov 11, 2009, 11:12:54 AM11/11/09
to rubyonra...@googlegroups.com
If what you want is a single migration to replace the multiple migrations you had you can do it but maybe not easily.  As Marnen said you can recreate the schema.rb from the database using an existing rake task.  If you really want a migration you can then bring that file into any editor and change the syntax line by line to the migration syntax.  It is not hard but just fairly tedious.  If you just want to have the ability to recreate the database, just create the schema.rb (see above) and save it into your configuration management system.  You can fetch it and run it any time to recreate the current database configuration.

Norm
Reply all
Reply to author
Forward
0 new messages