问题
I have a Rails 4 application that uses ActiveRecord to interact with a PostgreSQL 9.3 database. The application makes use of the hstore
extension in PostgreSQL for storing key-value pairs in a single database field. Accordingly, Rails automatically detects what I did with that migration and creates the following line in your schema.rb file
enable_extension "hstore"
In the development and test environments, that works great, as I am deploying to stand-alone PostgreSQL instances. However in production, I am deploying to a PostgreSQL instance in Amazon RDS, where the extension must be installed by a member of the rds_superuser
group. I'd rather not put my application user in that role.
Is there a way to make the execution of that code dependent on the environment? For example, run the code in development in test, but not on deploys to production?
I've tried creating a migration that's conditional, but it doesn't eliminate the line above when the schema is generated. Example:
class ModifyHstoreSetup < ActiveRecord::Migration
def self.up
if %w(staging, production).include?(ENV["RAILS_ENV"] || "development")
enable_extension "plpgsql"
enable_extension "hstore"
end
end
def self.down
if %w(staging, production).include?(ENV["RAILS_ENV"] || "development")
disable_extension "plpgsql"
disable_extension "hstore"
end
end
end
回答1:
Just make your user member of rds_superuser group. Then your migration will succeed.
来源:https://stackoverflow.com/questions/20986262/enabling-the-hstore-extension-in-amazon-rds-from-rails-4