Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Dave Alexander
Dave Alexander
4,894 Points

Deploying ruby on rails app - migrations, schema.rb - best practices

I have started to build a ruby on rails app. As I develop the app, I am realizing some models require more columns/index (so I create migrations).

My question is, when the app is complete, and I want to put it into production, what is the best way to set up the models and database? I notice that in the schema.rb file, the tables have all the correct columns/index from the migrations.

Do I need to keep the past migrations I have created? Or can I delete them?

When I actually deploy the app, will the tables be created from the schema.rb file? I have read some forums mentioning db.reset and db.setup. Are these necessary?

Thank you :)

2 Answers

You do not want to delete the migrations. They build on top of one another. The schema is composed of going through your earliest migration to the latest migration.

From the docs:

db:setup is a shortcut for: db:create, db:schema:load, db:seed

db:reset is a shortcut for: db:drop, db:setup

Dave Alexander
Dave Alexander
4,894 Points

Thanks Charles,

Would there be any benefit to me basically rebuilding the models /app with the correct columns initially set it, rather than having multiple migrations?