Test RDBMS should == production RDBMS

In Mikamai we developed svelto, our own url shortener application in 2008, but at that time the web was still on IPv4 (and it mostly is today, for what it matters). When registering visits we store also the visitor’s remote ip, and a few days ago we received a visit from an IPv6 number which ended up in an application error:

Mysql2::Error: Data too long for column 'remote_ip'
at row 1: INSERT INTO `visits` (
  `created_at`, `remote_ip`, `shorty_id`, `updated_at`, `user_agent`
  '2016-04-10 19:08:44', '2600:1011:b126:3242:9f8c:89ba:c2cd:1299'

The issue was caused by a column size limit on the remote_ip field. The limit was set at 15 chars, enough only for IPv4.

I immediately wrote a regression test in order to expose the issue but… no red sign after running it, it passed right away!
The reason was that the test environment was using Sqlite3 RDBMS instead of Mysql, as all other environments did.

After fixing this issue the test was now red, with the problem exposed and ready for fix (easy fix, of course… I added a migration and alter the limit of the coulumn to 45 chars in order to address the IPV6 format).

TL;DR: you should use the same RDBMS setup in all your application environments, as long as there is no real reason to make them different, or you could get a bite!

Leave a Reply

Please Login to comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.