Re: [pg_search] How to configure PostgreSQL test database before testing

1,222 views
Skip to first unread message

Grant Hutchins

unread,
Oct 25, 2012, 10:22:25 PM10/25/12
to casecom...@googlegroups.com
Hello,

The commands you listed look correct to me. Have you tried putting them into a migration instead of seeds? I tend to consider these sorts of things part of the schema rather than data that is to be seeded. That said, I would still expect what you wrote to work.

The actual problem, I'm guessing, is that your test database is not picking up the extension. This can happen if you're still using schema.rb to store your schema. Since Active Record doesn't directly support things like PostgreSQL extensions, text search dictionaries, etc., you will need to make this change in your environment.rb

config.active_record.schema_format = :sql
That way, when you run rake db:test:prepare, it will use SQL to duplicated the structure of the development database into the test database.

Let us know if this works for you. Thanks!

-- 
Grant Hutchins

On Wednesday, October 24, 2012 at 4:15 AM, ida...@gmail.com wrote:

I'm using pg_search to get PostgreSQL's full-text search working in my Rails project. I'm using the "unaccent" extension, and I have written the following in my seeds.rb file to load the extension in my development environment:

ActiveRecord::Base.connection.execute("CREATE EXTENSION unaccent;")
ActiveRecord::Base.connection.execute("ALTER TEXT SEARCH DICTIONARY unaccent (RULES='unaccent');")
ActiveRecord::Base.connection.execute("CREATE TEXT SEARCH CONFIGURATION es ( COPY = spanish );")
ActiveRecord::Base.connection.execute("ALTER TEXT SEARCH CONFIGURATION es
  ALTER MAPPING FOR hword, hword_part, word
  WITH unaccent, spanish_stem;"
)

This works perfectly in develpment.

Now I want to run some functional search tests, but I get an error saying that the extension is not configured:

ActiveRecord::StatementInvalid: PG::Error: ERROR:  function unaccent(text) does not exist

So I assume I have to do the same that I did for development, but for the test environment, isn't it?

Or maybe there is another approach?

--
 
 
 

Grant Hutchins

unread,
Oct 25, 2012, 10:40:00 PM10/25/12
to casecom...@googlegroups.com, gr...@nertzy.com
By the way, there is a wiki page about this as well.


Grant
Reply all
Reply to author
Forward
0 new messages