postgresql - Rails/Postgres brittle test environment not creating correct datatypes -
i'm using citext
extension because of postgres's shortcoming respect not having global feature allow case-insensitive searching.
however, in rails 3.2 application when run:
rake db:test:prepare
my objects created text
datatypes, instead of citext
. how can force above rake command create database , add extensions application requires in order kind of searching should baked in already?
you need add citext extension test database. unfortunately, in standard implementation of db:test:prepare database dropped , recreated, extension gone.
i found myself in same situation , had resort override db:test:purge (which called prior prepare) own implementation instead of dropping database drop objects (a solution based on 'drop owned username').
update rake task code: rake task looks this. put on lib/tasks/overrides/database.rake; that's you.
namespace :db namespace :test task :purge => [] rake::task["purge"].clear # desc overrides default task drop objects in database instead of db (only postgresql) task :purge => [:environment, :load_config] abcs = activerecord::base.configurations case abcs['test']['adapter'] when /postgresql/ # original implementation commented out #activerecord::base.clear_active_connections! #drop_database(abcs['test']) #create_database(abcs['test']) drop_database_objects(abcs['test']) end end end end def drop_database_objects(config) case config['adapter'] when /postgresql/ activerecord::base.establish_connection(config) sql = "drop owned #{config['username']}" activerecord::base.connection.execute sql end end
i omitting parts haven't changed, can see original @ database.rake. note: found postgresql 9.2.2 has problem drop owned by, you'll fine using 9.2.1 , 9.2.3; it's 1 version.
Comments
Post a Comment