我有以下迁移:
class CreateNoAccentFunction < ActiveRecord::Migration
def up
execute <<-SQL
CREATE OR REPLACE FUNCTION no_accent(text) RETURNS text AS $$
SELECT translate($1,'omitted', 'omitted');
$$
LANGUAGE sql IMMUTABLE STRICT;
SQL
end
def down
execute "DROP FUNCTION IF EXISTS no_accent(text)"
end
end
如果我在开发中运行rake db:migrate
,它将创建该函数。但它并没有在测试环境中。我尝试使用rake db:test:prepare
,rake db:reset
,rake db:schema:load
,但没有一个会执行我的CREATE FUNCTION
。只有rake db:drop & rake db:create & rake db:migrate
似乎有效。为什么呢?