Rails 4.2 / PostgreSQL和测试数据库准备

时间:2015-04-24 06:46:48

标签: ruby-on-rails postgresql rake

我们正在使用Rake::Task['db:create'].enhance添加新架构并在新创建的架构中创建扩展,如下所示。

Rake::Task['db:create'].enhance do
  ActiveRecord::Base.connection.execute('CREATE SCHEMA IF NOT EXISTS shared_extensions;')
  ActiveRecord::Base.connection.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA shared_extensions;')
end

我们能否以同样的方式增强测试数据库的准备?

1 个答案:

答案 0 :(得分:0)

在Wiki中为公寓宝石找到了答案。

Rake::Task["db:test:purge"].enhance do
  ActiveRecord::Base.connection.execute('CREATE SCHEMA IF NOT EXISTS shared_extensions;')
  ActiveRecord::Base.connection.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA shared_extensions;')
end