使用Rails 4.2对TimescaleDB数据库运行RSpec测试套件 [英] Running an RSpec test suite against a TimescaleDB database with Rails 4.2

查看:273
本文介绍了使用Rails 4.2对TimescaleDB数据库运行RSpec测试套件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要与TimescaleDB数据库一起使用的Rails 4.2.11.1应用程序.

I have a Rails 4.2.11.1 application that I am trying to use with a TimescaleDB database.

我已经解决了大多数问题(使用composite_primary_keys gem来解决Timescale的限制,即唯一索引应始终包含表的timestamp列).

I've solved the majority of the issues already (using the composite_primary_keys gem to get around Timescale's restriction that unique indexes should always include the table's timestamp column).

这具有我的应用程序的全部功能,但是当我尝试写入Timescale表时,我的测试套件会失败,并出现以下错误:

This has my application fully functional, but my test suite fails whenever I try to write to the Timescale table, with the following error:

PG::FeatureNotSupported: ERROR:  invalid INSERT on the root table of hypertable "events"
HINT:  Make sure the TimescaleDB extension has been preloaded.

据我所知,Rails并未在测试数据库中启用扩展.这适用于我正在使用的任何模式转储模式(:sql:ruby).使用bundle exec rails dbconsole手动连接到数据库,可以看到扩展已启用.

As far as I can tell, Rails is not enabling the extension within the test database; this applies whichever schema dumping mode I'm using (either :sql or :ruby). Connecting to the database manually with bundle exec rails dbconsole, I can see that the extension is enabled.

我不确定这是我的代码,Timescale还是Rails的错误,但是这使我无法交付此更改.

I'm not sure whether this is a bug with my code, with Timescale, or with Rails, but it's stopping me from being able to ship this change.

我希望其他人以前遇到过这种情况并且能够提供帮助!

I'm hoping that someone else has come across this scenario before and is able to help!

推荐答案

在Rails 6.0.2.2/TimescaleDB 1.7.0(在Minitest上)上,我遇到了同样的问题.

I had the same problem on Rails 6.0.2.2 / TimescaleDB 1.7.0 (On Minitest).

当我从sql模式转储切换回ruby模式转储时,问题已解决.

The problem was solved, when I switched from sql schema dump back to ruby schema dump.

config.active_record.schema_format = :ruby # (in application.rb)

显然,sql格式的模式转储包含错误/是部分错误,并且从中进行准备就引入了错误(db:test:clone).

Apparently, the schema dump of the sql format contained errors/was partial, and preparing from it introduced the error (db:test:clone).

希望对您有帮助.

这篇关于使用Rails 4.2对TimescaleDB数据库运行RSpec测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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