Reputation: 9776
I've recently started using Ruby on Rails, after previously using Django for web development. I'm finding myself quite liking the emphasis on migrations (which on Django is an afterthought), but am a bit concerned by the following:
I suppose one could be disciplined in naming the migration files, and so it is doable to find all migrations pertaining to a given model, but still, once you get to, say, m
models with n
migrations each, that's a lot to keep track.
There must be a way to inspect the current state of a particular model -- fields and methods both -- without the drudgery; could a more seasoned RoR developer enlighten me?
Upvotes: 1
Views: 113
Reputation: 6036
If you look at your model files, you'll notice that they don't contain references to their properties - for instance, your User might have an email, yet there is no trace of it in your User.rb. That is because it resides in schema.rb.
Schema.rb
is a representation of your database generated by rails from your database when running rake db:migrate. While it's not the end of the world if you delete it - running your migrations should (theoretically) result in the schema.rb
you have. However, migrations are brittle things (you might have added new validation rules since a migration was originally written, for example) so therefore, you should have schema.rb
checked into version control.
Schema.rb can be loaded into an empty database by running
rake db:schema:load
Upvotes: 1
Reputation: 16435
You have the db/schema.rb
file, where all the fields of each model are expressed (in the form of one big migration).
The separation between data (fields) and behavior (methods) is intentional, and it can be overridden using libraries which annotate the models with a copy of the latest applicable schema in the head comment
Upvotes: 3