Skip to content

Conversation

@calmacleod
Copy link

@calmacleod calmacleod commented Nov 21, 2025

Resolve Scenic Integration Causes Issues with Multiple Databases by adding optional configuration block with option to disable Scenic integration

@CLAassistant
Copy link

CLAassistant commented Nov 21, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@murrayju murrayju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the submission! Just a bit of feedback, if you don't mind addressing it.

@calmacleod
Copy link
Author

calmacleod commented Dec 22, 2025

@murrayju Please note that I also bumped some tool versions to ensure that the project is up to date when running the tests locally.

For what it's worth, to get all the tests running locally, I had to make some changes to some surrounding code. I haven't committed it yet but it may be worth it to get it included.

Specifically the test helper teardown_tables doesn't properly handle dropping materialized views and the ContinuousAggregates model doesn't seem to scope jobs/chunks properly in it's has_many relationships.

diff --git a/lib/timescaledb/continuous_aggregates.rb b/lib/timescaledb/continuous_aggregates.rb
index 5c4e61f..85d4293 100644
--- a/lib/timescaledb/continuous_aggregates.rb
+++ b/lib/timescaledb/continuous_aggregates.rb
@@ -3,11 +3,15 @@ module Timescaledb
     self.table_name = "timescaledb_information.continuous_aggregates"
     self.primary_key = 'materialization_hypertable_name'
 
-    has_many :jobs, foreign_key: "hypertable_name",
-      class_name: "Timescaledb::Job"
+    has_many :jobs,
+    foreign_key: "hypertable_name",
+    primary_key: "view_name",
+    class_name: "Timescaledb::Job"
 
-    has_many :chunks, foreign_key: "hypertable_name",
-      class_name: "Timescaledb::Chunk"
+    has_many :chunks,
+    foreign_key: "hypertable_name",
+    primary_key: "materialization_hypertable_name",
+    class_name: "Timescaledb::Chunk"
 
     scope :resume, -> do
       {
diff --git a/spec/support/active_record/schema.rb b/spec/support/active_record/schema.rb
index 6924962..b0a2a91 100644
--- a/spec/support/active_record/schema.rb
+++ b/spec/support/active_record/schema.rb
@@ -36,6 +36,10 @@ def setup_tables
 end
 
 def teardown_tables
+  Timescaledb::ContinuousAggregates.all.each do |continuous_aggregate|
+    ActiveRecord::Base.connection.execute("DROP MATERIALIZED VIEW IF EXISTS #{continuous_aggregate.view_name} CASCADE")
+  end
+
   ActiveRecord::Base.connection.tables.each do |table|
     ActiveRecord::Base.connection.drop_table(table, force: :cascade)
   end

@calmacleod calmacleod requested a review from murrayju December 22, 2025 19:38
@murrayju
Copy link
Member

@calmacleod lets get the tests to pass in this PR. Please add your fixes

@calmacleod
Copy link
Author

@murrayju The PR has been updated with the following:

  • Updated bundler + gem version to take care of deprecation warnings
  • Updated the Schema Dumper spec to account for newer Active Record 8.1 method definitions
  • Added new testing.md document with detailed explanations for how the test suite can be run.

@murrayju
Copy link
Member

Thanks @calmacleod. It looks like the tests are still failing in the checks here. Can you take another look?

@calmacleod
Copy link
Author

@murrayju I've made some changes that should hopefully fix those CI failures - The workflow needs maintainer approval before it can run however.

@calmacleod
Copy link
Author

@murrayju There's some weird, potentially inconsistent, between local and CI testing.

This is the test failure I'm getting:

Failures:

  1) Timescaledb::MigrationHelpers.create_caggs when using refresh policies is expected not to be empty
     Failure/Error: expect(model.caggs.first.jobs).not_to be_empty
       expected `#<ActiveRecord::Associations::CollectionProxy []>.empty?` to be falsey, got true
     # ./spec/timescaledb/migration_helper_spec.rb:131:in `block (4 levels) in <top (required)>'

Initially I dealt with the same failure locally, however, I was able to get the test passing by modifying continuous_aggregates.rb to use view_name as a foreign key to the jobs table rather than materialization_hypertable_name.

This is because the cAgg refresh policy job gets created with the table name of the cAgg rather than the table name of the hyper table for which the cAgg is being created for.

The databases which we're testing against in CR are all 12m old images where as I'm using Timescale on PG18 to test locally, perhaps the structure between cAggs and Jobs have changed in newer versions?

The cAgg create by the test:

hypertable_schema hypertable_name view_schema view_name view_owner materialized_only compression_enabled materialization_hypertable_schema materialization_hypertable_name view_definition finalized
public ticks public ohlc_1m postgres true false _timescaledb_internal _materialized_hypertable_746 SELECT time_bucket('00:01:00'::interval, created_at) AS "time",symbol,first(price, created_at) AS open,max(price) AS high,min(price) AS low,last(price, created_at) AS close,sum(volume) AS volume FROM ticks GROUP BY (time_bucket('00:01:00'::interval, created_at)), symbol; true

And the refresh policy job created for the cAgg:

job_id application_name schedule_interval max_runtime max_retries retry_period proc_schema proc_name owner scheduled fixed_schedule config next_start initial_start hypertable_schema hypertable_name check_schema check_name
1264 Refresh Continuous Aggregate Policy [1264] 00:01:00 00:00:00 -1 00:01:00 _timescaledb_functions policy_refresh_continuous_aggregate postgres true false {"end_offset":"PT1M","start_offset":"P1M","mat_hypertable_id":407} 2026-01-09 16:27:39.415483+00 public ohlc_1m _timescaledb_functions policy_refresh_continuous_aggregate_check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scenic Integration Causes Issues with Multiple Databases

3 participants