Skip to content

[-] keep TimescaleDB hypertables in sink migration 01409, fixes #1614 - #1616

Open
pashagolub wants to merge 2 commits into
masterfrom
fix-1614-timescale-migration
Open

pashagolub wants to merge 2 commits into
masterfrom
fix-1614-timescale-migration

Conversation

@pashagolub

@pashagolub pashagolub commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

On TimescaleDB sinks, migration 01409 converted every hypertable into a native partitioned table and dropped its data. Sinks created by pgwatch v4 then failed with table "X" is already partitioned, because they still used the v4 admin.ensure_partition_timescale. Fixes #1614.

 01409 Switch to time-only partitioning
   reinstall admin functions
+  if schema_type = 'timescale'
+    return
   for each metric table
     rename, recreate as RANGE(time), move rows, drop old table

+01614 Reinstall ensure_partition_timescale

01409 is an applied migration, and this PR edits its body. That breaks the "never edit migrations" rule on purpose: a later migration can't protect sinks that haven't upgraded yet, because 01409 runs first and drops the data. The name and order stay the same, so sinks that already applied 01409 don't run it again.

Sinks that already ran the broken 01409 are not repaired. Their old data is gone, and recreating the sink is safer.

Evidence

  • Before: with 5.3.0 and then config upgrade from 6.0.0 on a TimescaleDB sink, the 35 hypertables became 0, all metric tables became native partitioned tables, and wal went from 1 row to 0.
    TestMigration_TimescaleHypertablesSurvive with the guard disabled:
    bootstrap a timescale sink, create hypertable ts_metric with 2 rows
    replace ensure_partition_timescale with an outdated stub
    run all migrations
    FAIL  ts_metric is a hypertable          (01409 must not convert hypertables)
    FAIL  ts_metric is not RANGE partitioned
    FAIL  ts_metric has 2 rows
    
    After: the same test passes, and ensure_partition_timescale('ts_metric_new') creates a hypertable. go test ./internal/sinks/... ./cmd/... passes, and golangci-lint reports 0 issues.

Merge Danger

Door: two-way

Revert the commit to undo it. The only schema change is a CREATE OR REPLACE FUNCTION with the current function body.

Blast Radius: TimescaleDB sinks

PostgreSQL sinks run 01409 as before. Sinks on schema 01529 get one new migration, so they need pgwatch config upgrade before 6.1.0 starts.

@coveralls

coveralls commented Oct 24, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 40083355021

Coverage decreased (-0.2%) to 87.643%

Details

  • Coverage decreased (-0.2%) from the base build.
  • Patch coverage: 16 uncovered changes across 2 files (10 of 26 lines covered, 38.46%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
internal/testutil/setup.go 14 0 0.0%
internal/sinks/postgres.go 12 10 83.33%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 6223
Covered Lines: 5454
Line Coverage: 87.64%
Coverage Strength: 1.0 hits per line

馃挍 - Coveralls

@pashagolub pashagolub self-assigned this Oct 24, 2026
@pashagolub
pashagolub requested a review from 0xgouda October 24, 2026 09:51
@pashagolub pashagolub added bug Something isn't working sinks Where and how to store monitored data labels Oct 24, 2026

This branch has not been deployed

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

Labels

bug Something isn't working sinks Where and how to store monitored data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrading to 6.0.0 from 5.3.0

2 participants