timescaledb
timescaledb copied to clipboard
None of the static class methods in the gem seem to work in a Rails app
I'm not sure whether this is a bug or user error, but in the Rails console, I can't use any of the static methods from the timescale gem. E.g. Timescaledb::Extension.version and Timescaledb::Stats.new([MyModel.hypertable]).to_h. So I also can't execute Timescaledb::Extension.update!. It seems that Timescaledb::Connection.instance is not initialized.
my_application(prod)> Timescaledb::Extension.installed?
(my_application):7:in '<main>': connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory (PG::ConnectionBad)
Is the server running locally and accepting connections on that socket?
my_application(prod)> Timescaledb::Connection.instance.connected?
=> false
I can't find any code that would initialize the connection when used within a Rails app. Should my app have a custom initializer that does so?
Hi @exterm, have you tried to establish the connection first?
Timescaledb.establish_connection(ENV['DATABASE_URL'])
You can check the bin/tsdb with the --stats option:
https://github.com/timescale/timescaledb-ruby/blob/a78398d782703dd0f142cfdfe24db79c72fb4a91/bin/tsdb#L7
I don't have a DATABASE_URL env var on my application server, so I'd have to build it from the Rails configuration. I'll look into that.
It would be nice for timescaledb-ruby to come with a railtie that inserts an initializer to initialize the connection. Or somehow reuse ActiveRecord's connection.
that's a great point @exterm. I'm looking to make it a seamless integration. Let's discover how to make it through railties.