Is it possible to do Reverse Engineering in rails migrations?

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

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

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,

sathishkumar sadhasivam wrote:


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

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