Ruby on Rails: Migrations Vs. SQL

So you’re learning or using Ruby on Rails, or even just using Ruby with a database. The ActiveRecord component of Rails provides one way to work with databases through Ruby. ActiveRecord applies a concept called ORM (Object Relational Mapping) to quite literally map object oriented programming constructs to relational database constructs.

What’s that mean? It means it you can write Ruby in a fairly Ruby way (to be fair to purists, a Rails way) when working with databases. Most folks will be using an SQL-based relational database, such as MySQL, PostreSQL or SQLite3. Others are possible, but MySQL is certainly the most common and probably best supported.

Specifically, Rails uses an approach called database migrations to substitute for writing SQL directly. Migrations make things pretty easy, indeed. You can learn plenty about using migrations with the main book for Rails, Agile Web Development With Rails. However, I encourage everyone to also take a look to the book, Ruby for Rails.

The general approach of Ruby for Rails is to get you to know how the magic works, and help you develop a better understanding of the underlying technology so you can do more with it. This is really a key thing. You’re not going to be good at Rails without learning Ruby itself, much less CSS, XHTML, and perhaps Javascript, and definitely a little SQL.

What?! Yeah. That’s right, you do need to know about the details. Perhaps not intimately, but well enough to understand what it is you’re really doing. SQL is a big subject. Lucky for you, database-driven web sites tend to do a lot of the same kinds of things in most situations. Therefore, you don’t need to be a master of SQL but you need to experience it and understand how it works. Particularly MySQL’s version (and if you’re a programmer, consider SQLite as well)

SQL isn’t that hard, but it is fairly different from most other programming languages. (yes, I think it IS a programming language.) But I don’t just want you to know SQL a little, I want you to know a little database design too. This is what is important so you will have some concept of what it is migrations is doing for you. When you have this in your head, you will then also know what migrations may not be able to do for you.

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment