-
Notifications
You must be signed in to change notification settings - Fork 882
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72bb953
commit 22cf7e4
Showing
3 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
## {{ release_current }} ({{ release_date }}) | ||
|
||
This release contains performance improvements and bug fixes since | ||
the {{ release_previous }} release. We recommend that you upgrade at the next | ||
available opportunity. | ||
|
||
In addition, it includes these noteworthy features: | ||
* foo | ||
* bar | ||
|
||
**For on-premise users and this release only**, you will need to run the following SQL script after running `ALTER EXTENSION`. More details can be found in the pull request [#6786](https://github.com/timescale/timescaledb/pull/6797). | ||
|
||
```sql | ||
CREATE OR REPLACE FUNCTION pg_temp.constraint_columns(regclass, int2[]) RETURNS text[] AS | ||
$$ | ||
SELECT array_agg(attname) FROM unnest($2) un(attnum) LEFT JOIN pg_attribute att ON att.attrelid=$1 AND att.attnum = un.attnum; | ||
$$ LANGUAGE SQL SET search_path TO pg_catalog, pg_temp; | ||
|
||
DO $$ | ||
DECLARE | ||
ht_id int; | ||
ht regclass; | ||
chunk regclass; | ||
con_oid oid; | ||
con_frelid regclass; | ||
con_name text; | ||
con_columns text[]; | ||
chunk_id int; | ||
|
||
BEGIN | ||
|
||
-- iterate over all hypertables that have foreign key constraints | ||
FOR ht_id, ht in | ||
SELECT | ||
ht.id, | ||
format('%I.%I',ht.schema_name,ht.table_name)::regclass | ||
FROM _timescaledb_catalog.hypertable ht | ||
WHERE | ||
EXISTS ( | ||
SELECT FROM pg_constraint con | ||
WHERE | ||
con.contype='f' AND | ||
con.conrelid=format('%I.%I',ht.schema_name,ht.table_name)::regclass | ||
) | ||
LOOP | ||
RAISE NOTICE 'Hypertable % has foreign key constraint', ht; | ||
|
||
-- iterate over all foreign key constraints on the hypertable | ||
-- and check that they are present on every chunk | ||
FOR con_oid, con_frelid, con_name, con_columns IN | ||
SELECT con.oid, con.confrelid, con.conname, pg_temp.constraint_columns(con.conrelid,con.conkey) | ||
FROM pg_constraint con | ||
WHERE | ||
con.contype='f' AND | ||
con.conrelid=ht | ||
LOOP | ||
RAISE NOTICE 'Checking constraint % %', con_name, con_columns; | ||
-- check that the foreign key constraint is present on the chunk | ||
|
||
FOR chunk_id, chunk IN | ||
SELECT | ||
ch.id, | ||
format('%I.%I',ch.schema_name,ch.table_name)::regclass | ||
FROM _timescaledb_catalog.chunk ch | ||
WHERE | ||
ch.hypertable_id=ht_id | ||
LOOP | ||
RAISE NOTICE 'Checking chunk %', chunk; | ||
IF NOT EXISTS ( | ||
SELECT FROM pg_constraint con | ||
WHERE | ||
con.contype='f' AND | ||
con.conrelid=chunk AND | ||
con.confrelid=con_frelid AND | ||
pg_temp.constraint_columns(con.conrelid,con.conkey) = con_columns | ||
) THEN | ||
RAISE WARNING 'Restoring constraint % on chunk %', con_name, chunk; | ||
PERFORM _timescaledb_functions.constraint_clone(con_oid, chunk); | ||
INSERT INTO _timescaledb_catalog.chunk_constraint(chunk_id, dimension_slice_id, constraint_name, hypertable_constraint_name) VALUES (chunk_id, NULL, con_name, con_name); | ||
END IF; | ||
|
||
END LOOP; | ||
END LOOP; | ||
|
||
END LOOP; | ||
|
||
END | ||
$$; | ||
|
||
DROP FUNCTION pg_temp.constraint_columns(regclass, int2[]); | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters