Improve updated test

Adds a FK constraint, check constraint, and exclusion constraint to the
update test.
This commit is contained in:
Matvey Arye 2017-12-19 11:22:18 -05:00 committed by Matvey Arye
parent 68faddca24
commit ca85ec4865
3 changed files with 20 additions and 5 deletions

View File

@ -3,10 +3,15 @@ CREATE DATABASE single;
\c single
CREATE EXTENSION IF NOT EXISTS timescaledb;
CREATE TABLE devices (
id TEXT PRIMARY KEY,
floor INTEGER
);
CREATE TABLE PUBLIC."two_Partitions" (
"timeCustom" BIGINT NOT NULL,
device_id TEXT NOT NULL,
series_0 DOUBLE PRECISION NULL,
device_id TEXT NOT NULL REFERENCES devices(id),
series_0 DOUBLE PRECISION NOT NULL CHECK(series_0 > 0),
series_1 DOUBLE PRECISION NULL,
series_2 DOUBLE PRECISION NULL,
series_bool BOOLEAN NULL,
@ -21,6 +26,10 @@ CREATE INDEX ON PUBLIC."two_Partitions" ("timeCustom" DESC NULLS LAST, device_id
SELECT * FROM create_hypertable('"public"."two_Partitions"'::regclass, 'timeCustom'::name, 'device_id'::name, associated_schema_name=>'_timescaledb_internal'::text, number_partitions => 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
INSERT INTO devices(id,floor) VALUES
('dev1', 1),
('dev2', 2);
INSERT INTO public."two_Partitions"("timeCustom", device_id, series_0, series_1, series_2) VALUES
(1257987600000000000, 'dev1', 1.5, 1, 1),
(1257987600000000000, 'dev1', 1.5, 2, 2),
@ -33,7 +42,10 @@ INSERT INTO "two_Partitions"("timeCustom", device_id, series_0, series_1, series
CREATE TABLE PUBLIC.hyper_timestamp (
time timestamp NOT NULL,
device_id TEXT NOT NULL,
value int NOT NULL
value int NOT NULL,
EXCLUDE USING btree (
"time" WITH =, device_id WITH =
) WHERE (value > 0)
);
SELECT * FROM create_hypertable('hyper_timestamp'::regclass, 'time'::name, 'device_id'::name, number_partitions => 2,

View File

@ -35,6 +35,8 @@ SELECT index_name FROM _timescaledb_catalog.chunk_index ORDER BY index_name;
\d+ _timescaledb_internal._hyper*
-- INSERT data to create a new chunk after update or restore.
INSERT INTO devices(id,floor) VALUES
('dev5', 5);
INSERT INTO "two_Partitions"("timeCustom", device_id, series_0, series_1, series_2) VALUES
(1258894000000000000, 'dev5', 2.2, 1, 2);
@ -83,6 +85,7 @@ BEGIN
FOR constraint_row IN
SELECT c.conname, h.id AS hypertable_id FROM _timescaledb_catalog.hypertable h INNER JOIN
pg_constraint c ON (c.conrelid = format('%I.%I', h.schema_name, h.table_name)::regclass)
WHERE c.contype != 'c'
LOOP
SELECT count(*) FROM _timescaledb_catalog.chunk c
WHERE c.hypertable_id = constraint_row.hypertable_id
@ -96,7 +99,7 @@ BEGIN
INTO STRICT chunk_constraint_count;
IF chunk_constraint_count != chunk_count THEN
RAISE EXCEPTION 'Missing chunk constraints. Expected %, but found %', chunk_count, chunk_constraint_count;
RAISE EXCEPTION 'Missing chunk constraints for %. Expected %, but found %', constraint_row.conname, chunk_count, chunk_constraint_count;
END IF;
END LOOP;
END;

View File

@ -5,6 +5,6 @@ SELECT * FROM _timescaledb_catalog.tablespace ORDER BY id;
SELECT id, hypertable_id, column_name, column_type, aligned, num_slices, interval_length FROM _timescaledb_catalog.dimension ORDER BY id;
SELECT * FROM _timescaledb_catalog.dimension_slice ORDER BY dimension_id, range_start, range_end;
SELECT * FROM _timescaledb_catalog.chunk ORDER BY id;
SELECT * FROM _timescaledb_catalog.chunk_constraint ORDER BY chunk_id, dimension_slice_id, constraint_name;
SELECT chunk_id, dimension_slice_id, hypertable_constraint_name, constraint_name IS NULL FROM _timescaledb_catalog.chunk_constraint ORDER BY chunk_id, dimension_slice_id, hypertable_constraint_name;
--index name changed, so don't output that
SELECT hypertable_index_name, hypertable_id, chunk_id FROM _timescaledb_catalog.chunk_index ORDER BY hypertable_index_name, hypertable_id, chunk_id;