-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact(db): Replace get_deleted_tables function with a view
This function was returning the set of deletion tables. A view seems better suited for this task since it would allow for applying additional filters of the result set. This was particularly necessary to easily make changes to some sqltests due to switching the delete trigger for the session table.
- Loading branch information
Showing
5 changed files
with
51 additions
and
5 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
18 changes: 18 additions & 0 deletions
18
internal/db/schema/migrations/oss/postgres/91/05_deletion_tables_view.up.sql
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,18 @@ | ||
-- Copyright (c) HashiCorp, Inc. | ||
-- SPDX-License-Identifier: BUSL-1.1 | ||
|
||
begin; | ||
-- Originially added in 81/01_deleted_tables_and_triggers.up.sql | ||
-- This is being replaced with a view. | ||
drop function get_deletion_tables; | ||
|
||
-- This view uses the pg_catalog to find all tables that end in _deleted and are visibile. | ||
-- See: https://www.postgresql.org/docs/current/catalog-pg-class.html | ||
-- https://www.postgresql.org/docs/current/functions-info.html#FUNCTIONS-INFO-SCHEMA | ||
create view deletion_table as | ||
select c.relname as tablename | ||
from pg_catalog.pg_class c | ||
where c.relkind in ('r') -- r = ordinary table | ||
and c.relname operator(pg_catalog.~) '^(.+_deleted)$' collate pg_catalog.default | ||
and pg_catalog.pg_table_is_visible(c.oid); | ||
commit; |
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
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
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