Want to dump a legacy database to a schema.rb file from a JDBC connection? Yeah, me neither, but I have to. Since ActiveRecord is working, I can just use the SchemaDumper, right? That’s basically true, but, as of JRuby 0.9.0, I need a few additional tweaks.
For starters, the JDBC adapter doesn’t implement an indexes method. Since I’m not worried about capturing the index information right now, I just added this hack:
module ActiveRecord module ConnectionAdapters class JdbcAdapter def indexes(table);;end end end end
This is just for unit testing for now, so the missing index information isn’t a problem. If you need this information, you’ll probably have to write your own indexes implementation. I think it can probably be added to the JdbcSpec for the specific database you’re supporting, but I haven’t actually tried it myself. I was thinking about trying that this weekend, so I may have some code for that next week.
The other problem I have is that JRuby 0.9.0 has a bug in the StringIO#puts method. Calling puts without an argument does not add a new line character to the stream. The result is a schema.rb file that doesn’t parse. My schema is over 1800 lines long, so I’m not about to try adding all the new lines myself. I filed a bug report and uploaded a patch here.
With a my indexes hack and a patched JRuby, my schema seems to be generating. Now to see if it will load…