Created
August 28, 2013 12:57
-
-
Save blasterpal/6365745 to your computer and use it in GitHub Desktop.
Add read only user to PG 9 on DB, cookbook snippet.
This file contains hidden or 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
| # Create a user with Login | |
| sql = [%(CREATE ROLE jsmith WITH PASSWORD 'foobar' LOGIN)] | |
| # # Allow to connect | |
| sql << %(GRANT CONNECT ON DATABASE reports TO jsmith) | |
| # # Allow to use schema | |
| sql << %(GRANT USAGE ON SCHEMA public TO jsmith) | |
| # # grant on current objects | |
| sql << %(GRANT SELECT ON ALL TABLES IN SCHEMA public TO jsmith) | |
| # # grant on future objects | |
| sql << %(ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO jsmith) | |
| %x(psql reports postgres -c "#{sql.join(';')}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment