-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify table marking utility methods.
- Loading branch information
1 parent
8bec2aa
commit 73522b6
Showing
13 changed files
with
76 additions
and
94 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 |
---|---|---|
@@ -1,55 +1,55 @@ | ||
-- | ||
-- accounts | ||
-- | ||
CALL diffix.mark_personal('public', 'accounts', 'account_id'); | ||
CALL diffix.mark_personal('accounts', 'account_id'); | ||
ALTER TABLE accounts ADD CONSTRAINT accounts_pkey PRIMARY KEY (account_id); | ||
|
||
-- | ||
-- accounts_receivables | ||
-- | ||
CALL diffix.mark_personal('public', 'accounts_receivables', 'customerid'); | ||
CALL diffix.mark_personal('accounts_receivables', 'customerid'); | ||
|
||
-- | ||
-- credit_cards | ||
-- | ||
CALL diffix.mark_personal('public', 'credit_cards', 'disp_id'); | ||
CALL diffix.mark_personal('credit_cards', 'disp_id'); | ||
|
||
-- | ||
-- clients | ||
-- | ||
CALL diffix.mark_personal('public', 'clients', 'client_id'); | ||
CALL diffix.mark_personal('clients', 'client_id'); | ||
|
||
ALTER TABLE clients ADD CONSTRAINT clients_pkey PRIMARY KEY (client_id); | ||
|
||
-- | ||
-- dispositions | ||
-- | ||
CALL diffix.mark_personal('public', 'dispositions', 'client_id', 'account_id'); | ||
CALL diffix.mark_personal('dispositions', 'client_id', 'account_id'); | ||
|
||
ALTER TABLE dispositions ADD CONSTRAINT dispositions_pkey PRIMARY KEY (disp_id); | ||
|
||
-- | ||
-- loans | ||
-- | ||
CALL diffix.mark_personal('public', 'loans', 'account_id'); | ||
CALL diffix.mark_personal('loans', 'account_id'); | ||
|
||
ALTER TABLE loans ADD CONSTRAINT loans_pkey PRIMARY KEY (loan_id); | ||
|
||
-- | ||
-- loss_events | ||
-- | ||
SECURITY LABEL FOR pg_diffix ON TABLE loss_events IS 'public'; | ||
CALL diffix.mark_public('loss_events'); | ||
|
||
-- | ||
-- orders | ||
-- | ||
CALL diffix.mark_personal('public', 'orders', 'account_id', 'account_to'); | ||
CALL diffix.mark_personal('orders', 'account_id', 'account_to'); | ||
|
||
ALTER TABLE orders ADD CONSTRAINT orders_pkey PRIMARY KEY (order_id); | ||
|
||
-- | ||
-- transactions | ||
-- | ||
CALL diffix.mark_personal('public', 'transactions', 'account_id'); | ||
CALL diffix.mark_personal('transactions', 'account_id'); | ||
|
||
ALTER TABLE transactions ADD CONSTRAINT transactions_pkey PRIMARY KEY (trans_id); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,47 +39,29 @@ AS $$ | |
$$ | ||
SECURITY INVOKER SET search_path = ''; | ||
|
||
CREATE PROCEDURE mark_personal(table_namespace text, table_name text, variadic aid_columns text[]) | ||
CREATE PROCEDURE mark_personal(table_name text, variadic aid_columns text[]) | ||
AS $$ | ||
DECLARE | ||
table_oid integer := (SELECT pg_class.oid | ||
FROM pg_class, pg_namespace | ||
WHERE pg_class.relnamespace = pg_namespace.oid AND relname = table_name AND nspname = table_namespace); | ||
table_fullname text := quote_ident(table_namespace) || '.' || quote_ident(table_name); | ||
aid_column text; | ||
BEGIN | ||
IF (SELECT @[email protected]_level()) <> 'direct' THEN | ||
RAISE EXCEPTION '"mark_personal" requires direct access mode.'; | ||
END IF; | ||
DELETE FROM pg_catalog.pg_seclabel WHERE provider = 'pg_diffix' AND objoid = table_name::regclass::oid AND label = 'aid'; | ||
|
||
DELETE FROM pg_catalog.pg_seclabel WHERE provider = 'pg_diffix' AND objoid = table_oid AND label = 'aid'; | ||
|
||
EXECUTE 'SECURITY LABEL FOR pg_diffix ON TABLE ' || table_fullname || ' IS ''personal'''; | ||
EXECUTE 'SECURITY LABEL FOR pg_diffix ON TABLE ' || table_name || ' IS ''personal'''; | ||
|
||
FOREACH aid_column IN ARRAY aid_columns LOOP | ||
EXECUTE 'SECURITY LABEL FOR pg_diffix ON COLUMN ' || table_fullname || '.' || quote_ident(aid_column) || ' IS ''aid'''; | ||
EXECUTE 'SECURITY LABEL FOR pg_diffix ON COLUMN ' || table_name || '.' || aid_column || ' IS ''aid'''; | ||
END LOOP; | ||
END; | ||
$$ LANGUAGE plpgsql | ||
SECURITY INVOKER SET search_path = ''; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE PROCEDURE mark_public(table_namespace text, table_name text) | ||
CREATE PROCEDURE mark_public(table_name text) | ||
AS $$ | ||
DECLARE | ||
table_oid integer := (SELECT pg_class.oid | ||
FROM pg_class, pg_namespace | ||
WHERE pg_class.relnamespace = pg_namespace.oid AND relname = table_name AND nspname = table_namespace); | ||
BEGIN | ||
DELETE FROM pg_catalog.pg_seclabel WHERE provider = 'pg_diffix' AND objoid = table_oid AND label = 'aid'; | ||
DELETE FROM pg_catalog.pg_seclabel WHERE provider = 'pg_diffix' AND objoid = table_name::regclass::oid AND label = 'aid'; | ||
|
||
EXECUTE 'SECURITY LABEL FOR pg_diffix ON TABLE ' | ||
|| quote_ident(table_namespace) | ||
|| '.' | ||
|| quote_ident(table_name) | ||
|| ' IS ''public'''; | ||
EXECUTE 'SECURITY LABEL FOR pg_diffix ON TABLE ' || table_name || ' IS ''public'''; | ||
END; | ||
$$ LANGUAGE plpgsql | ||
SECURITY INVOKER SET search_path = ''; | ||
$$ LANGUAGE plpgsql; | ||
|
||
/* ---------------------------------------------------------------- | ||
* Common aggregation interface | ||
|
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
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
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
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