how to get ActiveRecord Schema Dumper to dump out larger columns 96
(This assumes you are using mysql, but similar changes will work for postgres, etc.)
If you are using Ruby on Rails and are trying to store large objects in a column, you may run into the following problem:
create_table :bogus do |t|
t.text :big_column, :limit => 1024*1024
endThat will create the table as expected, but mysql with automatically turn the text column into mediumtext (rails/ActiveRecord has no idea). The same think can happen with longtext, mediumblog, longblob, etc.
That’s all well and good, but when you run schema dumper (e.g., rake db:schema:dump), you’ll get this:
create_table :bogus do |t|
t.text :big_column
endand then you are screwed. Especially when you go to run tests (which can invoke the schema dumping).
There is a fairly easy fix for this. There is even a patch for it on the rails trac site (thanks Will Bryant!). But, until it gets fixed in the rails core…
Assuming you are using Rails 2.0 (edgerails as of now), which introduces support for initializers, create a file config/intializers/active_record_tweak.rb:
##
## from http://dev.rubyonrails.org/ticket/7424
##
module ActiveRecord
module ConnectionAdapters
class MysqlColumn
private
def extract_limit(sql_type)
if sql_type =~ /blob|text/i
case sql_type
when /tiny/i
255
when /medium/i
16777215
when /long/i
2147483647 # mysql only allows 2^31-1, not 2^32-1, somewhat inconsistently with the tiny/medium/normal cases
else
super # we could return 65535 here, but we leave it undecorated by default
end
else
super
end
end
end
end
end(If you have an earlier version of Rails, just put this code in config/environment.rb)
This isn’t perfect – the original limit information in your migration will get lost, replaced with whatever the maximum is for that column, but it’s a quick fix to get everything working again.
NOTE: If this solves a problem you were having, please go to the original ticket on railstrac and add a comment (you have to register and login to add a comment) saying:
+1 solves the problem without side-effects for me
(See this report for more info on this comment.)
Tab-completion in IRB 37
I came across this while poking around programming is hard which led me to the rails wiki
Make this your ~/.irbrc and enjoy tab completion:
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:LOAD_MODULES] = [] unless
IRB.conf.key?(:LOAD_MODULES)
unless IRB.conf[:LOAD_MODULES].include?(‘irb/completion’)
IRB.conf[:LOAD_MODULES] << ‘irb/completion’
end
Aaah. Sweet, sweet laziness.
Getting typo installed under debian 51
Installing typo on my OS X box was a breeze (assuming one already had rails installed, etc. etc.).
However, when I went to install it on my linux vhost running Debian 3.1, I ran into a few issues.
First, I had to sudo gem install mkmf.
Then I got this error
checking for sqlite3.h... no
And then a bunch of banging-head-against-the-wall ensued because after googling and discovering I need to do:
sudo apt-get install sqlite3 libsqlite3-dev
I then got this error:
checking for sqlite3_open() in -lsqlite3... no
So I looked in the logs:
less /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/ext/sqlite3_api/mkmf.log)
for more detail. It seemed to indicate that the sqlite3 lib didn’t have sqlite3_open in it. An objdump of the lib revealed that to be untrue. The actual errors of note in the file were:
conftest.c: In function `t':
conftest.c:4: warning: implicit declaration of function `sqlite3_open'
/usr/lib/libc_nonshared.a(elf-init.oS)
(.gnu.linkonce.t.__i686.get_pc_thunk.bx+0x0): In function `__i686.get_pc_thunk.bx':
: multiple definition of `__i686.get_pc_thunk.bx'
/tmp/cci4MfWc.o
(.gnu.linkonce.t.__i686.get_pc_thunk.bx+0x0):
/tmp/sqlite3-ruby-1.1.0/conftest.c:3: first defined here
collect2: ld returned 1 exit status
After typing a bunch of stuff by hand, I realized that my rbconfig.rb was gashmongled. Specifically, -fPIC was declared too many times and that was producing another error (too many thunks), which was the actual error to care about in the log.
sudo vim /usr/lib/ruby/1.8/i486-linux/rbconfig.rb
look for -fPIC on the cflags line and remove it.
Then, and only then, does
sudo gem install typo
actually run to completion. Ahhhhh…
(As an aside, during this process, I ended up installing my own version of sqlite3, but I don’t know if that was necessary).