我目前正在运行Rails迁移,在其中我要添加特定于Postgres的数据类型tsvector.它以Postgres期望的内置文本搜索功能的形式保存搜索信息.
I'm currently running a Rails migration where I am adding a datatype specific to Postgres, the tsvector. It holds search information in the form that Postgres expects for its built-in text searching capabilities.
这是我的迁移行:
t.column "search_vectors", :tsvector一切似乎都可以正常工作,并且搜索也可以正常工作.但是,当我打开schema.rb时,这就是我得到的:
Everything seems to be working fine, and the search works with it. However, when I opened up schema.rb, this is what I got:
Could not dump table "users" because of following StandardError Unknown type 'tsvector' for column 'search_vectors'这使我无法在用户表上运行单元测试,并且由于schema.rb应该是我数据库的权威定义,这使我感到非常危险.
This is preventing me from running unit tests on the user table, and also strikes me as really dangerous looking given that the schema.rb is supposed to be the authoritative definition of my database.
我注意到有许多Rails插件似乎使用了与我期望的相同的tsvector存储方法,例如tsearchable.我真的只是在没有测试并且没有对数据库进行权威定义的情况下坚持吗?
I notice there are a number of Rails plugins that seem to use the same approach of storing the tsvector like I would expect, such as tsearchable. Am I really just stuck without testing and without an authoritative definition of my database?
推荐答案对于在此页面上发生的任何人,仅供参考,我通过将其添加(实际上取消注释)到我的Rails配置中来解决此问题: config.active_record.schema_format =:sql
FYI for anyone who happens across this page, I fixed this by adding this (actually uncommenting it) to my Rails config: config.active_record.schema_format = :sql
更多推荐
使用特定于数据库的数据类型进行Rails迁移
发布评论