My website uses PostgreSQL and its full-text search. For that to work, I need to execute some configuration queries in order to configure some full-text search extensions. This is what I have written in a migration file to configure the development database: class ConfigurePostgresql < ActiveRecord::Migration def up execute("CREATE EXTENSION unaccent;") execute("ALTER TEXT SEARCH DICTIONARY unaccent (RULES=''unaccent'');") execute("CREATE TEXT SEARCH CONFIGURATION es ( COPY = spanish );") execute("ALTER TEXT SEARCH CONFIGURATION es ALTER MAPPING FOR hword, hword_part, word WITH unaccent, spanish_stem;") end end This works perfectly in develpment. Now I want to run some search tests, but when I execute my functional tests, I get an error saying that the extension is not configured: ActiveRecord::StatementInvalid: PG::Error: ERROR: function unaccent(text) does not exist Why is not it creating the extension? I have executed rake db:test:prepare -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/aTDph2KTQw8J. For more options, visit https://groups.google.com/groups/opt_out.
David M
2012-Oct-24 11:06 UTC
Re: How to configure a PostgreSQL test database before testing?
I have noticed that those execute lines are not included in my schema.rb. When I copy them inside the schema.rb, then all tests run correctly. Is there some way to make this work well without having to copy the executes everytime I make a migration? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/FSgIE-8rh50J. For more options, visit https://groups.google.com/groups/opt_out.
Jim Ruther Nill
2012-Oct-24 11:10 UTC
Re: How to configure a PostgreSQL test database before testing?
On Wed, Oct 24, 2012 at 6:49 PM, David M <idavemm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> My website uses PostgreSQL and its full-text search. For that to work, I > need to execute some configuration queries in order to configure some > full-text search extensions. > > This is what I have written in a migration file to configure the > development database: > > class ConfigurePostgresql < ActiveRecord::Migration > def up > execute("CREATE EXTENSION unaccent;") > execute("ALTER TEXT SEARCH DICTIONARY unaccent (RULES=''unaccent'');") > execute("CREATE TEXT SEARCH CONFIGURATION es ( COPY = spanish );") > execute("ALTER TEXT SEARCH CONFIGURATION es > ALTER MAPPING FOR hword, hword_part, word > WITH unaccent, spanish_stem;") > end > end > > This works perfectly in develpment. > > Now I want to run some search tests, but when I execute my functional > tests, I get an error saying that the extension is not configured: > > ActiveRecord::StatementInvalid: PG::Error: ERROR: function unaccent(text) does not exist > > Why is not it creating the extension? I have executed rake db:test:prepare >i think rake db:test:prepare uses schema.rb to create the test database. since you added raw sql, this is not added to schema.rb. you should use the sql format of schema.rb. more info here http://guides.rubyonrails.org/migrations.html#schema-dumping-and-you> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/aTDph2KTQw8J. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
David M
2012-Oct-24 11:30 UTC
Re: How to configure a PostgreSQL test database before testing?
Thanks jim, that solved the problem. El miércoles, 24 de octubre de 2012 13:11:57 UTC+2, jim escribió:> > > > On Wed, Oct 24, 2012 at 6:49 PM, David M <ida...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>>wrote: > >> My website uses PostgreSQL and its full-text search. For that to work, I >> need to execute some configuration queries in order to configure some >> full-text search extensions. >> >> This is what I have written in a migration file to configure the >> development database: >> >> class ConfigurePostgresql < ActiveRecord::Migration >> >> def up >> execute("CREATE EXTENSION unaccent;") >> >> execute("ALTER TEXT SEARCH DICTIONARY unaccent (RULES=''unaccent'');") >> >> execute("CREATE TEXT SEARCH CONFIGURATION es ( COPY = spanish );") >> >> execute("ALTER TEXT SEARCH CONFIGURATION es >> ALTER MAPPING FOR hword, hword_part, word >> >> WITH unaccent, spanish_stem;") >> end >> end >> >> This works perfectly in develpment. >> >> Now I want to run some search tests, but when I execute my functional >> tests, I get an error saying that the extension is not configured: >> >> ActiveRecord::StatementInvalid: PG::Error: ERROR: function unaccent(text) does not exist >> >> Why is not it creating the extension? I have executed rake >> db:test:prepare >> > i think rake db:test:prepare uses schema.rb to create the test database. > since you added raw sql, this is not added to schema.rb. you should use > the sql format of schema.rb. more info here > http://guides.rubyonrails.org/migrations.html#schema-dumping-and-you > > >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:> >> . >> To unsubscribe from this group, send email to >> rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/aTDph2KTQw8J. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > > -- > ------------------------------------------------------------- > visit my blog at http://jimlabs.heroku.com >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/59dVXZj0MKcJ. For more options, visit https://groups.google.com/groups/opt_out.