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:
- in Django, using a library like South, the migrations are automatically generated from the change you make to the models. So examining a single file or directory is enough to see the current definition of all your models
- in Rails, AFAIU, app/models/*.rb only contain those models’ methods; the fields are scattered throughout db/migrations.
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?
You have the
db/schema.rbfile, 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