1

I am working with a Rails project that uses UUIDs, through the uuid-ossp extension.

This is done through what looks to me like a standard migration:

class EnableExtensions < ActiveRecord::Migration
  def change
    enable_extension 'plpgsql'
    enable_extension 'uuid-ossp' if Rails.env.development? || Rails.env.test?
  end
end

However, working with this requires that I manually go around and set the extension to be enabled with a postgres superuser for each database:

-- enable_extension("uuid-ossp")
rake aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  permission denied to create extension "uuid-ossp"
HINT:  Must be superuser to create this extension.
: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"

I'm not going to give my user, or the rails project users, superuser privileges on any of my databases--that doesn't seem like a good habit. So how am I supposed to do this?

Note: this question's accepted answer doesn't answer the larger question in the title.

Community
  • 1
  • 1
bright-star
  • 6,016
  • 6
  • 42
  • 81
  • 1
    Based on [this](http://stackoverflow.com/a/20745157/143238) answer to a similar question about heroku (linked from the question you mentioned as not being a duplicate), https://github.com/dimitri/pgextwlist will allow you to whitelist extensions without having to grant superuser privileges. – BM5k May 10 '16 at 03:36
  • @BM5k I'll accept that as an answer if you post one about it. – bright-star May 10 '16 at 16:33

2 Answers2

4

Apparently https://github.com/dimitri/pgextwlist will allow you to whitelist extensions without having to grant superuser privileges.

Found as an answer to Why can only a superuser CREATE EXTENSION hstore, but not on Heroku?

Community
  • 1
  • 1
BM5k
  • 1,210
  • 10
  • 28
1

Probably the best approach in the event where you cannot go through the standard migrations process is to enable the extensions in template1 and that way they are there on every new db you create. Just remember if restoring a backup that used pg_dump to copy template0 rather than the default of template1.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182