views:

161

answers:

3

So this is my first real Ruby on Rails project. I've learned my lesson -- I didn't make all changes using migrations so things are a bit messed up.

What's the best way to start over with new migration files and rebuild the schema, etc? My project is too far along to rebuild the entire project, but not far enough along to where I care about losing the migrations I have thus far. I also don't mind losing the data in the database. I was trying to rollback to the beginning but some of it is failing.

I know this is a bad state to be in, but lesson learned.

EDIT: I just deleted all the migrations files and rebuilt the schema file with db:schema:dump. I assume this puts me in a clean state with my existing database, just lost migrations.

A: 

If you are not concerned about losing data then do

rake db:purge

It should just drop your database

nas
A: 

Your schema.rb file should contain the actual schema from your database. You could use it as a starting point to create you migrations. You could create a new migration for each table with the :force => true parameter to overwrite the old table. Afterwards you could just delete the old migrations (you would probably also need to delete their entries from schema_migrations table).

Another options would be just updating the old migrations to match your current schema.

Tomas Markauskas
Thanks -- I just deleted the migrations, emptied the schema_migrations table, then ran 'rake db:reset'. My schema wasn't fully up to date so I had to make some tweaks to the db after that. If I have to do this again I would do the same thing but try to figure out if there's a way to recreate the schema file from the current status of the db.
99miles
A: 

if you want to migrate some steps back you can

rake db:rollback STEP=2

That command will migrate your database 2 migrations back. If you need more help with rake commands, jus type

rake -T

That command will list all the tasks you have in you application.

Boris Barroso