Hacker News new | ask | show | jobs
by senotrusov 2936 days ago
Rails provide ruby DLS for migrations but you can always put plain SQL in that migration files. I do this most of the time and the Rails conveniently tracks which script needs to be executed against particular database state and runs them for me.

I find myself rarely do triggers. Not because I can't. It's just more handy to do on the ActiveRecord layer having access to all my ruby code.

Indexes, indexes on PL/pgsql procedures, foreign keys and constraints – they absolutely have their place in Rails applications.

Although you could do a rather complicated SELECT's with ActiveRecord, sometimes, for particular queries, I prefer to create a database VIEW and then point the ActiveRecord model to it.

1 comments

> Although you could do a rather complicated SELECT's with ActiveRecord, sometimes, for particular queries, I prefer to create a database VIEW and then point the ActiveRecord model to it.

Database views + ActiveRecord are a super power.