这两个奇怪的查询在每个请求上都会运行什么?

时间:2013-06-18 23:26:03

标签: ruby-on-rails postgresql ruby-on-rails-4

我将miniprofiler添加到我的应用程序中,我注意到以下两个查询在每个请求上运行,无论控制器或视图如何:

**GET http://acme.app.dev:80
T+4.3 ms
Reader
0.7 ms
              SELECT COUNT(*)
              FROM pg_class c
              LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
              WHERE c.relkind in ('v','r')
              AND c.relname = 'schema_migrations'
              AND n.nspname = ANY (current_schemas(false))

GET http://acme.app.dev:80/search
T+6.8 ms
Reader
0.2 ms
              SELECT "schema_migrations".* FROM "schema_migrations"   
              4.60 ms   
              Executing action: new — 2.60 ms

我的应用程序中没有任何内容可以运行它们。它们是什么,为什么它们总是在运行?我正在使用Rails 4和Postgresql。

1 个答案:

答案 0 :(得分:2)

Rails 4.0似乎会检查每个请求上的任何未完成的迁移。如果有未完成的迁移,我会在浏览器中收到此错误:

ActiveRecord::PendingMigrationError

Migrations are pending; run 'rake db:migrate RAILS_ENV=development' to resolve this issue.

我认为这只发生在测试/开发环境中,并且很可能与您在{test,spec} _helper.rb中看到的代码相同:

ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)