timescaledb
timescaledb copied to clipboard
How to upgrade timescale in a Rails application
I'm unsure how to do timescale updates in Rails. There is a Timescaledb::Extension.update! but it does not work. I guess I would have to have a migration that does something like
ApplicationRecord.connection.execute('ALTER EXTENSION timescaledb UPDATE')
?
I tried to execute that last statement in the console, but it didn't work:
/usr/local/bundle/ruby/3.4.0/gems/activerecord-8.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:160:in 'PG::Connection#exec': ERROR: extension "timescaledb" cannot be updated after the old version has already been loaded (PG::FeatureNotSupported)
HINT: Start a new session and execute ALTER EXTENSION as the first command. Make sure to pass the "-X" flag to psql.
I assume it would also not work in a migration since it would not be the first statement executed. I'm working on making the update part of an initialization script for my docker container (we're using Kamal to manage the production deployment of Timescale).
Hi @exterm, can you try to make a new connection to guarantee it's the first command?
Related issue: https://github.com/timescale/timescaledb/issues/1003
Also, this comment explains why it works like this.
I never used Kamal, but I'd also love to add instructions on how it works in the repository.
So, since we're using the docker image (through Kamal), we have to start a new container anyway. We can do the upgrade from the commandline in a separate session on container startup.
Thank you for the added explanation though, I misunderstood and thought it needed to be the first command after booting the server.