Module: PgSaurus::Migration::SetRoleMethod
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/pg_saurus/migration/set_role_method.rb
Overview
Wrap original ‘exec_migration` to run migration with set postgresql role. If config.ensure_role_set=true but no role is set for the migration, then an exception is raised.
Instance Method Summary collapse
-
#exec_migration_with_role(conn, direction) ⇒ void
Wrap original ‘exec_migration` to run migration with set role.
-
#keep_default_role? ⇒ Boolean
:nodoc:.
-
#role ⇒ Object
Get role.
Instance Method Details
#exec_migration_with_role(conn, direction) ⇒ void
This method returns an undefined value.
Wrap original ‘exec_migration` to run migration with set role.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pg_saurus/migration/set_role_method.rb', line 51 def exec_migration_with_role(conn, direction) if role begin conn.execute "SET ROLE #{role}" exec_migration_without_role(conn, direction) ensure conn.execute "RESET ROLE" end elsif PgSaurus.config.ensure_role_set && !keep_default_role? msg = "Role for migration #{self.class} is not set\n\n" \ "You've configured PgSaurus with ensure_role_set=true. \n" \ "That means that every migration must explicitly set role with set_role method.\n\n" \ "Example:\n" \ " class CreateNewTable < ActiveRecord::Migration\n" \ " set_role \"superhero\"\n" \ " end\n\n" \ "If you want to set ensure_role_set=false, take a look at config/initializers/pg_saurus.rb\n\n" raise PgSaurus::RoleNotSetError, msg else exec_migration_without_role(conn, direction) end end |
#keep_default_role? ⇒ Boolean
:nodoc:
41 42 43 |
# File 'lib/pg_saurus/migration/set_role_method.rb', line 41 def keep_default_role? self.class.keep_default_role? end |
#role ⇒ Object
Get role
36 37 38 |
# File 'lib/pg_saurus/migration/set_role_method.rb', line 36 def role self.class.role end |