fix(migration): use PERFORM for add_compression_policy inside DO block#182
Conversation
Bare SELECT inside a PL/pgSQL DO block is invalid when the result is discarded — Postgres raises 42601 "query has no destination for result data". Switch the four add_compression_policy calls to PERFORM so the migration applies cleanly on TimescaleDB. Follows #179, #180, #181 — same file, same DO block.
Greptile SummaryReplaces four Confidence Score: 5/5Safe to merge — the four-line change is correct PL/pgSQL and precisely fixes the stated runtime error. The fix is surgically scoped, PL/pgSQL-correct, and the existing if_not_exists => true guard ensures idempotency. No logic, security, or correctness issues introduced. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[DO $$ BEGIN] --> B{timescaledb extension\nexists?}
B -- No --> C[RAISE NOTICE: skipping]
B -- Yes --> D[ALTER TABLE PipelineMetric SET compress options]
D --> E[PERFORM add_compression_policy PipelineMetric]
E --> F[ALTER TABLE NodeMetric SET compress options]
F --> G[PERFORM add_compression_policy NodeMetric]
G --> H[ALTER TABLE PipelineLog SET compress options]
H --> I[PERFORM add_compression_policy PipelineLog]
I --> J[ALTER TABLE NodeStatusEvent SET compress options]
J --> K[PERFORM add_compression_policy NodeStatusEvent]
K --> L[RAISE NOTICE: policies enabled]
C --> M[END $$]
L --> M
Reviews (1): Last reviewed commit: "fix(migration): use PERFORM for add_comp..." | Re-trigger Greptile |
Summary
Fourth in the TimescaleDB-demo bring-up bug series (after #179, #180, #181). Once #181 fixed the camelCase identifier quoting, the migration hit yet another error on a fresh TimescaleDB volume:
Inside a PL/pgSQL
DOblock, a bareSELECTis illegal unless its result is captured (SELECT ... INTO). To discard the result, you must usePERFORM. The fouradd_compression_policy(...)calls in this migration useSELECT, so the very first one aborts the whole block.The four
ALTER TABLE ... SET (timescaledb.compress, ...)statements in the same block are fine — only theadd_compression_policycalls need fixing.Fix
Four-line change. Each
SELECT add_compression_policy(becomesPERFORM add_compression_policy(. Table names, options, indentation untouched.Why this didn't surface earlier
Same as #179 / #180 / #181: every prior deployment ran on plain Postgres, where the
IF EXISTS (... timescaledb)guard makes this whole migration a no-op. Now that the prior three PRs let the body actually execute under TimescaleDB, this latent PL/pgSQL syntax bug is the next one in line.Recovery instructions
For anyone whose DB is currently in the failed state on this migration:
Option A — wipe and reapply (cleanest if no real data, e.g. demo):
Option B — preserve data:
Drift warning for plain-Postgres users
Same caveat as #179 / #180 / #181: the migration's checksum changes. On next
prisma migrate deployyou may see a "migration was modified after applied" warning. Resolve with:One-time fix; the no-op behaviour on plain Postgres is unchanged.
Test plan
SELECT add_compression_policy(→PERFORM add_compression_policy(docker compose upagainsttimescale/timescaledb:2.16.0-pg16— both20260329000000and20260329000001apply cleanly through to completionSELECT hypertable_name, proc_name FROM timescaledb_information.jobs WHERE proc_name = 'policy_compression';— should return rows forPipelineMetric,NodeMetric,PipelineLog,NodeStatusEventPrior PRs in this series
create_hypertableidincompress_orderbyto satisfy unique-index constraintcompress_segmentby/compress_orderbyoption strings