Module: PgRls::Database::Prepared
- Defined in:
- lib/pg_rls/database/prepared.rb
Overview
Prepare database for test unit
Class Method Summary collapse
Class Method Details
.grant_user_credentials(name: PgRls.username, schema: 'public') ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pg_rls/database/prepared.rb', line 8 def grant_user_credentials(name: PgRls.username, schema: 'public') PgRls.admin_execute " DO\n $do$\n BEGIN\n IF NOT EXISTS (\n SELECT table_catalog, table_schema, table_name, privilege_type\n FROM information_schema.table_privileges\n WHERE grantee = '\#{name}'\n ) THEN\n GRANT ALL PRIVILEGES ON TABLE schema_migrations TO \#{name};\n GRANT USAGE ON SCHEMA \#{schema} TO \#{name};\n ALTER DEFAULT PRIVILEGES IN SCHEMA \#{schema}\n GRANT USAGE, SELECT\n ON SEQUENCES TO \#{name};\n ALTER DEFAULT PRIVILEGES IN SCHEMA \#{schema}\n GRANT SELECT, INSERT, UPDATE, DELETE\n ON TABLES TO \#{name};\n GRANT SELECT, INSERT, UPDATE, DELETE\n ON ALL TABLES IN SCHEMA \#{schema}\n TO \#{name};\n GRANT USAGE, SELECT\n ON ALL SEQUENCES IN SCHEMA \#{schema}\n TO \#{name};\n END IF;\n END;\n $do$;\n SQL\nend\n".squish |