Archive for the ‘mysql’ Category

Rails not respecting primary keys

Wednesday, April 18th, 2007

There is some issue with Ruby on Rails not respecting primary key and other settings on columns when it does a schema dump of the db. It does this when you use a non-standard id column e.g. tablename_id and not just id.

There is a patch floating about that fixes this but a simpler way is to uncomment config.active_record.schema_format = :sql in your environment.rb. It then uses SQL and not Ruby for your schema and it respects your databases.

Rails and foreign databases

Thursday, October 26th, 2006

We are getting to a point in our project where we want the different bits to start integrating. One part is Java, another is C++ and the part I am responsible for is Ruby on Rails. All of this runs off of a MySQL 5 database.

The database schema is owned by a C++ guy and while he was willing to modify some of his style to fit Rails conventions I told him not to. To be honest I was worried when I said that. It was a risk thinking that Rails would be able to handle a non-standard database. Not only were primary and join tables named completely differently to Rails conventions but the columns were quite different and the data the one Rails app needed to get at was spread over multiple databases.

About 10 minutes ago I sat back in my creaky chair and sighed a sigh of relief. It all works. Rails handles the non-standard setup just fine.

We first made views of the underlying tables (which is why we are on MySQL 5) to get as close to Rails conventions as we could. It wasn’t perfect though as all our views are prefixed. By default Rails won’t handle that unless I bastardised my model naming which we weren’t going to do. The next trick was to use AustinMoody’s def self.table_name() “mpq.mpqs” end tip to tell Rails what table (actually, views) to use. It also solved the multiple-database problem as you just prefix the table name with the database name.

I then found out about the :join_table option on has_and_belongs_to_many in your models which deals with the join tables.

And that is all it took. I am relieved and impressed with Rails. I get all the good stuff while working on a decidely non-conventional Rails database setup.

RailsConf Europe 2006: Performance, RadRails and airlines

Thursday, September 14th, 2006

Three talks in and it is going fairly well. Soren Burkhart talk was billed as how they used Rails to revolutionise the airline industry. Untortunatley he spent too much time on the preliminaries and had to rush through the meat of his talk (the app and its development.) It looked interesting but we didn’t get into much detail. Might be worth contacting him directly to get some info.

James Cox’s talk on Rails performance and scaling (pdf) was pretty good. A chunk of my notes from it:

- columns => :select, pagination => :limit, :offset)
- @var ||= query
- MySQL is decent
- Memcache (doesn’t have to be on the same machine)
- mysql \s
- mysql - log slow queries - mysql_slow_queries
- nginx (russian but fast)
- mongrel for scaling even if it isn’t the fastest
- hostname lookup in apache2 bad

Matt Kent and Kyle Shank gave a demo of his RadRails IDE which seems to have come a long way from what I initially used. Auto-completion they want to do but apparently is a difficult feature.They are also working on porting TextMate Ruby snippets to RadRails. Certainly more featurefull than RIDE-ME at this stage. Autotest is a nifty way to run certain (or all) tests in the background on an interval or on save.

So far every talker has been young and inexperienced. Really smart but these aren’t slick conference speakers like you get at Java and Microsoft events. This is a good and bad thing. Good as you get low level info, bad because they can wander and be unprepared for the talk.

Flexibility

Wednesday, August 30th, 2006

I’ve spent the past hour or so with a co-worker trying to get a Cocoon+Java+RSS+MySQL+XSL+DELI system to do the simplest of tasks. What a nightmare. It is incredible in its flexiblitlity. I can’t think of much it can’t do. But what it does do is very little. It seems as though the chaps who built this system spent 90% of their time on the framework of the application and about 5% on the application itself. It has huge potential but all the bits that actually do things aren’t there. String replace? Nope. I had to find an XSL template that someone else had rewritten to get that.

It’s the autobahn without the Porsche. The scaffolding without the building. The bricks without the builder.

It’s cool and wonderful and so much fun to work with but ultimately it is insanity when all you want is to get the job done. The glass without the beer (thanks for that one, Elaine.)

This is where Ruby on Rails is kicking Java and .NET web-frameworks all over the park. They are visionary and capable of far more than Rails. But Rails actually does common tasks that you need to do. It is less flexible but ultimately more productive.

For those few edge cases that it can’t handle I’ll write a function in something else and pipe it in.