Method: ActiveRecord::PGExtensions::PostgreSQLAdapter#add_schema_to_search_path
- Defined in:
- lib/active_record/pg_extensions/postgresql_adapter.rb
permalink #add_schema_to_search_path(schema) ⇒ Object
temporarily adds schema to the search_path (i.e. so you can use an extension that won’t work without being on the search path, such as postgis)
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/active_record/pg_extensions/postgresql_adapter.rb', line 109 def add_schema_to_search_path(schema) if schema_search_path.split(",").include?(schema) yield else old_search_path = schema_search_path manual_rollback = false result = nil transaction(requires_new: true) do self.schema_search_path += ",#{schema}" result = yield self.schema_search_path = old_search_path rescue ActiveRecord::StatementInvalid, ActiveRecord::Rollback => e # the transaction rolling back will revert the search path change; # we don't need to do another query to set it @schema_search_path = old_search_path manual_rollback = e if e.is_a?(ActiveRecord::Rollback) raise end # the transaction call will swallow ActiveRecord::Rollback, # but we want it this method to be transparent raise manual_rollback if manual_rollback result end end |