Saturday, October 11, 2008

Two Problems

One of the things I knew and still ignored was checking in untested code is a bad idea. Compound that by ignoring said code for a few months allowing myself to forget the context of what I had done and I have a recipe for putting this project back together like Humpty Dumpty.

Technical Background:


To do the data import I run the command script/runner scripts/import/project.rb. That's not the problem, but it's important information. project.rb does the following

thesis_importer = ThesisImporter.new("directory for the legacy data files")
thesis_importer.load_project_data
ThesisImporter is a file in app/helper that holds the logic for how to parse the existing data files, putting the data in Model Objects, and saving them to the DB.

I have two problems:


1) Logging
The code in ThesisImporter used to be in a plain old script where I created a logger that I used throughout the code
logger = Logger.new(STDOUT)
 In theory when I run the script using script/runner there should be a logger available in the environment. BUT,  as soon as the process gets to the first line with a logger...
logger.info("this thing doesn't work at all")
...I get an error saying logger is an undefined variable. I know it's been a while but I thought the rails environment set up logger for me. So why can't I use it in a helper I'm calling from a script in with script/runner?



2) Database
So far I've been using the rails embedded sqllite DB, but it was an enormous pain to see any of the data in that database, so I decided to switch to mySQL. I installed MYSQL5.0, changed the encoding of both rails and mysql to "utf8" and fired it up. I was able to create the schema in mysql by calling

script/runner db/schema.rb
Now, if if go back to running my project.rb script above (commenting out ll the logging and replacing it with "puts" then I get an error as soon as I try to save an object where Bitnami Ruby Stack complains that I'm not using a production mysql binding in rails and I need to install the C binding for mysql. My code stops working there, so I try installing the C binding.

gem install mysql

The doc insstal appears to fail, but everything else (the actual binding install) works... I restart everything... Then when I run the project.rb script again I get the error saying I'm still using the wrong binding.

OK. It just occurred to me I'm dealing with two MYSQL instances. One from Bitnami and the one I installed last night. It's possible I'm doing the gem install that is somehow specific to the bitnami MYsql instance. However, my rails app is pointing at the NEW mysql 5.0 install from last night. I'll try pointing at the bitami install tonight.



Conclusion
I should never leave broken code alone for more than a few hours. Context is more useful than all the tea in china.

I still have no idea why the logging error is happening. I need to go look through some old rails code to see if I did something special to make logger.info available.

The MySql problem could be an issue with having two mysql installations that are fighting with each other.

I can't wait to get past these environment issues and get back to the actual project. More as this develops.

No comments: