Skip to content

Drop dependent caggs materialized views.#130

Open
rapito wants to merge 3 commits intotimescale:masterfrom
rapito:fix/clear-dependent-caggs-views-on-force-cascade
Open

Drop dependent caggs materialized views.#130
rapito wants to merge 3 commits intotimescale:masterfrom
rapito:fix/clear-dependent-caggs-views-on-force-cascade

Conversation

@rapito
Copy link

@rapito rapito commented Feb 22, 2026

Description

This PR fetches all caggs view dependencies of a table before deleting it to drop those first and avoid a potential dependency error that is not solved automatically by force: :cascade

Changes

  • Added helper method to schema_statements to fetch dependent views and execute drop materialized view on them.
  • Added drop_table to schema_statements and called the helper mentioned above.
  • Updated create_table to schema_statements and called the helper mentioned above.
  • Updated specs.

Context

When there are nested or dependent caggregations and create_table or drop_table are invoked with force: :cascade an error is raised indicating that the object cannot be deleted because another one depends on it.

This does not occur if a hyptertable has a single caggregation. But it does occur if you add a second layer and introduce another caggregation to the first one.

i.e:

  1. create table with hypertable option
  2. create a cagg with time_bucket of 1 hour on that table, named events_per_hour
  3. create another cagg with time_bucket of 1 day on events_per_day

You can see the behaviour by running this gist, or on the tests.

This causes that a migration that tries to override a table with such configuration fails.
Also, trying to run schema:load twice fails. (for whatever reason someone would need or want to do this)

@rapito rapito marked this pull request as ready for review February 22, 2026 21:20
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.

1 participant