使用特定于数据库的数据类型进行Rails迁移 [英] Rails migrations with database-specific data types

查看:97
本文介绍了使用特定于数据库的数据类型进行Rails迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在运行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迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆