timescaledb icon indicating copy to clipboard operation
timescaledb copied to clipboard

Multi-db setup

Open jamescook10 opened this issue 1 year ago • 3 comments

I'm experiencing issues when using this gem in a multi-db setup (standard Postgres primary DB with a second Timescale enabled DB).

It looks like the schema dumper is trying to dump timescale tables when this is run against the primary database. Obviously they won't be found, resulting in an error being raised.

Do you have any tips to getting this working? I'd be happy to submit a PR with a fix.

jamescook10 avatar Mar 12 '24 16:03 jamescook10

Hi @jamescook10, I think improving this scenario would be amazing!

@JamesMasonRC did great contributions on #10 and you can see the following files:

SchemaDumper maps the main logic: https://github.com/jonatas/timescaledb/blob/17e2383e613a6a30a136926ec4985c998bb7cacd/lib/timescaledb/schema_dumper.rb#L34-L46

lib/timescale/scenic/adapter.rb -> include views from continuous aggregates. https://github.com/jonatas/timescaledb/blob/17e2383e613a6a30a136926ec4985c998bb7cacd/lib/timescaledb/scenic/adapter.rb#L12-L18

One idea is introduce something that you can override the settings like config/initializers/timescaledb.rb and then you say something like:

SchemaDumper.config.expose_databases = [...]

or something to exclude dbs:

SchemaDumper.config.exclude_databases = [...]

By default it uses the connection but it could also navigate on this level.

Another option would be introduce it as a new module that you can just require "timescaledb/multi_databases" and it just fix the scenario when using new databases.

The ideal scenario would be identify the multi_db and understand what are the active configurations.

Your contribution will be very welcome 🤗

jonatas avatar Mar 13 '24 17:03 jonatas

I never used this before. Maybe that was my fault. I see now some examples that can also be useful here:

https://github.com/segiddins/timescaledb-rails/compare/main...crunchloop%3Atimescaledb-rails%3Amain

jonatas avatar Apr 12 '24 19:04 jonatas

I was thinking a bit better, maybe the best idea is just detects if the extension is installed and then skip in case it's not.

jonatas avatar May 02 '24 15:05 jonatas