Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ELE-3643: Add stored procedure and call to redshift permissions macro #753

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions macros/utils/cross_db_utils/get_profile_creation_query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ GRANT SELECT ON svv_table_info to {{ parameters["user"] }};

-- Grant access to columns information (svv_columns) in the warehouse
GRANT SELECT ON pg_catalog.svv_columns to {{ parameters["user"] }};

-- Create stored procedure for granting USAGE privilege for all schemas for metadata access
CREATE OR REPLACE PROCEDURE elementary_grant_usage_on_all_schemas(user_name VARCHAR)
LANGUAGE plpgsql
AS $$
DECLARE
schema_name RECORD;
BEGIN
-- Loop through all schemas in the current database
FOR schema_name IN
SELECT nspname
FROM pg_namespace
WHERE nspname NOT IN ('pg_catalog', 'information_schema') -- Exclude system schemas
LOOP
-- Grant USAGE privilege on each schema to the specified user
IF schema_name.nspname NOT IN ('pg_automv', 'pg_auto_copy', 'pg_s3', 'pg_mv') AND NOT CHARINDEX('/', schema_name.nspname) THEN
EXECUTE 'GRANT USAGE ON SCHEMA ' || schema_name.nspname || ' TO ' || user_name;
END IF;
END LOOP;
END;
$$;

-- Call the procedure to grant USAGE on all schemas to the specified user
CALL elementary_grant_usage_on_all_schemas('{{ parameters["user"] }}');
{% endmacro %}


Expand Down
Loading