Tuesday, June 26, 2007

ERWin for Free

Well not really but I finally found a suitable tool I can use for data modeling at home. Best of all is that it's freeware. Check out the Toad Data Modeler if you've been searching for an alternative. My favorite feature is that it exports DDL scripts to PostgreSQL :)

Unfortunately it only runs in Windows XP so I use it in a Parallels virtual machine.

Tuesday, June 19, 2007

How to backup PostgreSQL on OS X and *nix

It's wise to backup your database if you've got anything important in there (like the internet's next big thing). You could read through the documentation to see what else is going on or just run the following commands and get the job done.

To backup:
pg_dump -U your_username --clean --no-owner your_db_name > backup.sql

--clean tells Postgres to generate SQL to drop all objects in the database before recreating them. Comes in handy when you want to reinitialize your database and skip the createdb process.
--no-owner tells Postgres to disregard ownership in the dump and give it to the user who restores from that file. Not necessary but I use it when I restore prod data from my host to my local development db.

To restore:
psql -U your_username -d db_to_restore < backup.sql

Sanity check:
psql -U your_username -d your_db_name
=# \d
(should return a list of relations)
=# select * from some_table
(should show some expected data)

Friday, June 15, 2007

Using a string to invoke a method by its name

Tonight I was trying to create a fancy pie chart using the Gruff gem. I'm using column names as the hash key. The value is the total number of times that column was equal to true in the table.



I needed to count how many rows where that column is equal to true (select count(*) from topics where [column_name] = true). Having the column name and that total count made up a key/value pair in my hash. If a column has no occurrences of true, there's no sense in including it in my graph because it would just be 0%.

So the problem was not knowing which columns to represent in the pie graph until runtime. I could get the data from each column and use many if/else statements but I wanted a more dynamic solution. You never know when the clients want one or fifty more columns...

After some research I thought I could use Object#instance_variable_get(symbol) on an ActiveRecord object but it wasn't so. Attributes in ActiveRecord models aren't instance variables. With some help and great explanations from the OC Ruby users' group, I proceeded using Object.send(symbol) to get an attribute value by passing its name as a symbol.

In the end, I ended up not displaying the graph because the small sample didn't give much value to decision makers. Yet. Maybe I can show the top 5 favorite topics instead of this:



--

My recommended books. At the bottom are my most completely read books. As you go up they become more of a reference for me.

Thursday, June 7, 2007

First go-live

Bah, I take so much time to update. I've been pretty busy with Rails lately. That's great news though since I love learning new things. I bought the Flexible Rails pdf and have completed about half the tutorials. If you're serious about using Flex for your RoR front-end I don't know of a better resource.

I deployed my first Rails app this past Monday. Well I wouldn't really call it an application, more like a sign up form for summer camp. I plan to add some kind of Excel export and some reports using Gruff. This is just the beginning :) I'd like to build a Flex UI for the admins sometime this month. If I get around to doing that I'll post some screen shots to show off sexy.