Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a good way to clean up my migrations in Rails?

So I've been working on this web app for a year now and I would like to compile to schema into ONE migration, that way my text editor loads faster, git working directory isn't so cluttered.

Search find will be faster.

Any my config/db won't be 4000px long.

like image 311
fivetwentysix Avatar asked Jul 26 '11 02:07

fivetwentysix


People also ask

How does Rails keep track of migrations?

Every time a migration is generated using the rails g migration command, Rails generates the migration file with a unique timestamp. The timestamp is in the format YYYYMMDDHHMMSS . Whenever a migration is run, Rails inserts the migration timestamp into an internal table schema_migrations .

What does db reset do Rails?

db:reset: Resets your database using your migrations for the current environment. It does this by running the db:drop , db:create , db:migrate tasks. db:rollback: Rolls the schema back to the previous version, undoing the migration that you just ran.

Which command is true to rollback migration in Rails?

You must rollback the migration (for example with bin/rails db:rollback ), edit your migration, and then run bin/rails db:migrate to run the corrected version.


1 Answers

Remove the migration files once you've migrated your servers. If you ever want to start with a fresh deployment, run rake db:schema:load or rake db:setup. You shouldn't be re-running all your migrations as explained here.

like image 123
icecream Avatar answered Oct 26 '22 22:10

icecream