Articles tagged with database
Monday, December 10, 2007
Boolean Columns
Just found this little tidbit about returning a boolean from a tinyint column tonight on the rails wiki...
Columns which are either boolean or tinyint(1) are recognised as booleans by ActiveRecord. So, if you have a table “people” and a column “rocks tinyint(1)”, you can say:
person = People.find(1)
person.rocks = true
However, person.rocks will return an integer, and Ruby thinks that 0 is true. If you want to test for truth, use person.rocks?, like this view example:
<% if person.rocks? %>
You rock, dude!
<% end %>
I did not know that. Pretty dang cool.
Tuesday, May 30, 2006
Stored Procedures 2.0?
Coming from a Microsoft platform background, I’m well versed in the stored procedure mantra, which practically equates to “use them everywhere”. Over the past year or so, I’ve starting questioning that assumption. While stored procs are useful, they do more to add unneccessary complexity to application development.
Jeff Atwood offers up a compelling (yet slightly dated) argument for reducing the scope of stored procs in his post Who needs Stored Procedures, anyways?
For modern databases and real world usage scenarios, I believe a Stored Procedure architecture has serious downsides and little practical benefit. Stored Procedures should be considered database assembly language: for use in only the most performance critical situations. There are plenty of ways to design a solid, high performing data access layer without resorting to Stored Procedures; you’ll realize a lot of benefits if you stick with parameterized SQL and a single coherent development environment.
I now longer use stored procs when working with an application database. They become much more useful when dealing with an integration database. Martin Fowler captures the differences.
The real question to ask is, “Where am I spending my time?”. Am I doing application development where I can encapsulate my business logic into a single application layer? Or am I working with a database that multiple application must interact with where a clear business layer nearly impossible to maintain?
Though I still have a foot in both worlds, I have gravitated over the past few years toward much more application development. I simply enjoy it more. Hence, I find myself using stored procs less and less.
Wednesday, January 25, 2006
Backing up MySQL
After committing the cardinal sin on a recent project of killing the production database without a backup the day before launch, I spent some serious time figuring out a solid back up solution. Thankfully I found automysqlbackup. Thought the name lacks creativity, the script rocks! It’s a unix shell script that creates 5 running daily, weekly, and monthly backups of multiple MySQL databases in a very clean directory structure. It’s highly recommended if you are doing anything with MySQL.
Oh, and thankfully, the host had a backup of the database as of 1am that night. Whew!
Articles RSS Feed