Enabling the hstore extension in Amazon RDS from Rails 4

◇◆丶佛笑我妖孽 提交于 2020-05-13 04:27:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!