Skip to content

Commit 771e75e

Browse files
committed
Detach public views during extension downgrade
To allow user references on extension views detach our catalog views during extension downgrade similar to how we already do for extension update.
1 parent 77af4ab commit 771e75e

14 files changed

Lines changed: 109 additions & 66 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/sql/pre_install/*.gen
99
/sql/updates/*.gen
1010
/sql/updates/header.sql
11+
/sql/updates/views_detached.sql
1112
/data/
1213
/src/*.o
1314
/src/*.so

cmake/GenerateScripts.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function(generate_downgrade_script)
5959
include(
6060
${CMAKE_BINARY_DIR}/v${_downgrade_TARGET_VERSION}/cmake/ScriptFiles.cmake)
6161

62-
set(_downgrade_PRE_FILES "header.sql;${PRE_DOWNGRADE_FILES}")
62+
set(_downgrade_PRE_FILES "header.sql;views_detached.sql;${PRE_DOWNGRADE_FILES}")
6363
set(_downgrade_POST_FILES "${PRE_INSTALL_FUNCTION_FILES};${SOURCE_FILES}" ${POST_UPDATE_FILES})
6464

6565
# Fetch epilog from target version.

scripts/check_updates.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from pglast import parse_sql
88
from pglast.ast import ColumnDef
9+
from pglast.enums.parsenodes import ObjectType
910
from pglast.visitors import Visitor
1011
from pglast import enums
1112
import sys
@@ -178,6 +179,14 @@ def visit_CreateFunctionStmt(
178179
"_timescaledb_functions should be used as schema for internal functions",
179180
)
180181

182+
def visit_DropStmt(self, _ancestors, node):
183+
if node.removeType == ObjectType.OBJECT_VIEW:
184+
if node.objects[0][0].sval == "timescaledb_information":
185+
self.error(
186+
f"Attempting to drop view {node.objects[0][0].sval}.{node.objects[0][1].sval}",
187+
"Views in schema timescaledb_information must not be dropped in update scripts",
188+
)
189+
181190

182191
# copied from pgspot
183192
def visit_sql(sql):

scripts/test_updates.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ if [ -n "${VERSIONS}" ]; then
9191
for version in ${VERSIONS}; do
9292
ts_minor_version=$(echo "${version}" | awk -F. '{print $2}')
9393

94-
if [ "${ts_minor_version}" -ge 22 ]; then
94+
if [ "${ts_minor_version}" -ge 25 ]; then
95+
TEST_VERSION=v12
96+
elif [ "${ts_minor_version}" -ge 22 ]; then
9597
TEST_VERSION=v11
9698
elif [ "${ts_minor_version}" -ge 20 ]; then
9799
TEST_VERSION=v10

sql/updates/2.23.1--2.24.0.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_stat_history_retention;
2+
DROP VIEW IF EXISTS timescaledb_information.hypertables;
23
DROP VIEW IF EXISTS timescaledb_information.chunks;
4+
DROP VIEW IF EXISTS timescaledb_information.chunk_columnstore_settings;
5+
DROP VIEW IF EXISTS timescaledb_information.chunk_compression_settings;
36

47
-- Add support for concurrent merge_chunks()
58
CREATE TABLE _timescaledb_catalog.chunk_rewrite (
@@ -27,3 +30,4 @@ BEGIN
2730
END IF;
2831
END
2932
$$;
33+

sql/updates/2.24.0--2.25.0.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
DROP VIEW IF EXISTS timescaledb_information.dimensions;
2+
DROP VIEW IF EXISTS timescaledb_information.hypertables;
3+
DROP VIEW IF EXISTS timescaledb_information.chunks;
4+
DROP VIEW IF EXISTS timescaledb_information.chunk_columnstore_settings;
5+
DROP VIEW IF EXISTS timescaledb_information.chunk_compression_settings;
6+
27
-- Block update if CAggs in old format are found
38
DO
49
$$
@@ -252,3 +257,4 @@ DROP FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts
252257
DROP FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts TIMESTAMPTZ);
253258

254259
DROP FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts TIMESTAMPTZ, origin TIMESTAMPTZ);
260+

sql/updates/2.25.2--2.26.0.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ ALTER TABLE _timescaledb_catalog.compression_chunk_size DROP CONSTRAINT compress
1414
ALTER TABLE _timescaledb_catalog.compression_chunk_size DROP CONSTRAINT compression_chunk_size_compressed_chunk_id_fkey;
1515

1616
--drop dependent views
17-
DROP VIEW IF EXISTS timescaledb_information.hypertables;
18-
DROP VIEW IF EXISTS timescaledb_information.chunks;
1917
DROP VIEW IF EXISTS _timescaledb_internal.hypertable_chunk_local_size;
2018
DROP VIEW IF EXISTS _timescaledb_internal.compressed_chunk_stats;
21-
DROP VIEW IF EXISTS timescaledb_information.chunk_columnstore_settings;
22-
DROP VIEW IF EXISTS timescaledb_information.chunk_compression_settings;
2319

2420
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.chunk;
2521
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.chunk_id_seq;

sql/updates/latest-dev.sql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ CREATE TABLE _timescaledb_internal.tmp_dimension_slice_seq_value AS
7272
ALTER TABLE _timescaledb_catalog.chunk_constraint
7373
DROP CONSTRAINT IF EXISTS chunk_constraint_dimension_slice_id_fkey;
7474

75-
DROP VIEW IF EXISTS timescaledb_information.chunks;
76-
7775
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.dimension_slice;
7876
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.dimension_slice_id_seq;
7977

@@ -163,7 +161,6 @@ DROP FUNCTION _timescaledb_functions.chunk_constraint_add_table_constraint(
163161
_timescaledb_catalog.chunk_constraint);
164162
DROP FUNCTION IF EXISTS _timescaledb_internal.chunk_constraint_add_table_constraint(
165163
_timescaledb_catalog.chunk_constraint);
166-
DROP VIEW IF EXISTS timescaledb_information.chunks;
167164

168165
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.chunk_constraint;
169166
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.chunk_constraint_name;
@@ -187,9 +184,6 @@ ALTER TABLE _timescaledb_catalog.hypertable
187184

188185
-- Drop views and foreign keys that depend on the catalog table.
189186
DROP VIEW IF EXISTS timescaledb_experimental.policies;
190-
DROP VIEW IF EXISTS timescaledb_information.hypertables;
191-
DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates;
192-
DROP VIEW IF EXISTS timescaledb_information.jobs;
193187

194188
ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark
195189
DROP CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey;

sql/updates/reverse-dev.sql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ WHERE c.osm_chunk
4242
ON CONFLICT DO NOTHING;
4343

4444
-- Drop chunk stats related objects
45-
DROP VIEW IF EXISTS timescaledb_information.stat_chunk_activity;
4645
DROP FUNCTION IF EXISTS _timescaledb_functions.chunk_statistics(regclass, regclass, timestamptz);
4746
DROP FUNCTION IF EXISTS _timescaledb_functions.chunk_statistics_reset();
4847

@@ -91,8 +90,6 @@ CREATE TABLE _timescaledb_internal.tmp_dimension_slice AS
9190
CREATE TABLE _timescaledb_internal.tmp_dimension_slice_seq_value AS
9291
SELECT last_value, is_called FROM _timescaledb_catalog.dimension_slice_id_seq;
9392

94-
DROP VIEW IF EXISTS timescaledb_information.chunks;
95-
9693
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.dimension_slice;
9794
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.dimension_slice_id_seq;
9895

@@ -193,9 +190,6 @@ DROP FUNCTION IF EXISTS _timescaledb_functions.rebuild_sparse_index(REGCLASS, BO
193190
-- Rebuild the catalog table `_timescaledb_catalog.continuous_agg` to drop the
194191
-- `schema_change_timestamp` column.
195192
DROP VIEW IF EXISTS timescaledb_experimental.policies;
196-
DROP VIEW IF EXISTS timescaledb_information.hypertables;
197-
DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates;
198-
DROP VIEW IF EXISTS timescaledb_information.jobs;
199193

200194
ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark
201195
DROP CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey;

sql/views_detached.sql

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -168,51 +168,55 @@ SELECT
168168
NULL::text AS orderby,
169169
NULL::jsonb AS index;
170170

171-
CREATE OR REPLACE VIEW timescaledb_information.stat_chunk_activity AS
172-
SELECT
173-
NULL::regclass AS chunk,
174-
NULL::regclass AS compressed_chunk,
175-
NULL::integer AS chunk_id,
176-
NULL::integer AS hypertable_id,
177-
NULL::name AS hypertable,
178-
NULL::bigint AS compressed_batch_count,
179-
NULL::bigint AS compressed_block_count,
180-
NULL::bigint AS compressed_batch_rows_min,
181-
NULL::bigint AS compressed_batch_rows_max,
182-
NULL::bigint AS compressed_batch_rows_avg,
183-
NULL::double precision AS compressed_batch_rows_stddev,
184-
NULL::bigint AS compressed_batch_bytes_min,
185-
NULL::bigint AS compressed_batch_bytes_max,
186-
NULL::bigint AS compressed_batch_bytes_avg,
187-
NULL::double precision AS compressed_batch_bytes_stddev,
188-
NULL::bigint AS compressed_block_bytes_min,
189-
NULL::bigint AS compressed_block_bytes_max,
190-
NULL::bigint AS compressed_block_bytes_avg,
191-
NULL::double precision AS compressed_block_bytes_stddev,
192-
NULL::bigint AS total_batches_deleted,
193-
NULL::bigint AS total_batches_decompressed,
194-
NULL::bigint AS total_tuples_decompressed,
195-
NULL::bigint AS total_batches_scanned,
196-
NULL::bigint AS total_batches_checked_by_bloom,
197-
NULL::bigint AS total_batches_pruned_by_bloom,
198-
NULL::bigint AS total_batches_without_bloom,
199-
NULL::bigint AS total_batches_bloom_false_positives,
200-
NULL::bigint AS total_batches_filtered_compressed,
201-
NULL::bigint AS total_batches_filtered_decompressed,
202-
NULL::bigint AS last_op_batches_deleted,
203-
NULL::bigint AS last_op_batches_decompressed,
204-
NULL::bigint AS last_op_tuples_decompressed,
205-
NULL::bigint AS last_op_batches_scanned,
206-
NULL::bigint AS last_op_batches_checked_by_bloom,
207-
NULL::bigint AS last_op_batches_pruned_by_bloom,
208-
NULL::bigint AS last_op_batches_without_bloom,
209-
NULL::bigint AS last_op_batches_bloom_false_positives,
210-
NULL::bigint AS last_op_batches_filtered_compressed,
211-
NULL::bigint AS last_op_batches_filtered_decompressed,
212-
NULL::bigint AS n_selects,
213-
NULL::bigint AS n_inserts,
214-
NULL::bigint AS n_updates,
215-
NULL::bigint AS n_deletes,
216-
NULL::timestamptz AS first_update,
217-
NULL::timestamptz AS last_update;
218-
171+
DO $$
172+
BEGIN
173+
IF EXISTS (SELECT FROM pg_class WHERE relname = 'stat_chunk_activity' AND relkind = 'v') THEN
174+
CREATE OR REPLACE VIEW timescaledb_information.stat_chunk_activity AS
175+
SELECT
176+
NULL::regclass AS chunk,
177+
NULL::regclass AS compressed_chunk,
178+
NULL::integer AS chunk_id,
179+
NULL::integer AS hypertable_id,
180+
NULL::name AS hypertable,
181+
NULL::bigint AS compressed_batch_count,
182+
NULL::bigint AS compressed_block_count,
183+
NULL::bigint AS compressed_batch_rows_min,
184+
NULL::bigint AS compressed_batch_rows_max,
185+
NULL::bigint AS compressed_batch_rows_avg,
186+
NULL::double precision AS compressed_batch_rows_stddev,
187+
NULL::bigint AS compressed_batch_bytes_min,
188+
NULL::bigint AS compressed_batch_bytes_max,
189+
NULL::bigint AS compressed_batch_bytes_avg,
190+
NULL::double precision AS compressed_batch_bytes_stddev,
191+
NULL::bigint AS compressed_block_bytes_min,
192+
NULL::bigint AS compressed_block_bytes_max,
193+
NULL::bigint AS compressed_block_bytes_avg,
194+
NULL::double precision AS compressed_block_bytes_stddev,
195+
NULL::bigint AS total_batches_deleted,
196+
NULL::bigint AS total_batches_decompressed,
197+
NULL::bigint AS total_tuples_decompressed,
198+
NULL::bigint AS total_batches_scanned,
199+
NULL::bigint AS total_batches_checked_by_bloom,
200+
NULL::bigint AS total_batches_pruned_by_bloom,
201+
NULL::bigint AS total_batches_without_bloom,
202+
NULL::bigint AS total_batches_bloom_false_positives,
203+
NULL::bigint AS total_batches_filtered_compressed,
204+
NULL::bigint AS total_batches_filtered_decompressed,
205+
NULL::bigint AS last_op_batches_deleted,
206+
NULL::bigint AS last_op_batches_decompressed,
207+
NULL::bigint AS last_op_tuples_decompressed,
208+
NULL::bigint AS last_op_batches_scanned,
209+
NULL::bigint AS last_op_batches_checked_by_bloom,
210+
NULL::bigint AS last_op_batches_pruned_by_bloom,
211+
NULL::bigint AS last_op_batches_without_bloom,
212+
NULL::bigint AS last_op_batches_bloom_false_positives,
213+
NULL::bigint AS last_op_batches_filtered_compressed,
214+
NULL::bigint AS last_op_batches_filtered_decompressed,
215+
NULL::bigint AS n_selects,
216+
NULL::bigint AS n_inserts,
217+
NULL::bigint AS n_updates,
218+
NULL::bigint AS n_deletes,
219+
NULL::timestamptz AS first_update,
220+
NULL::timestamptz AS last_update;
221+
END IF;
222+
END $$;

0 commit comments

Comments
 (0)