[英]What's the simplest least-privilege way to enable UUIDs in a Rails schema?
I am working with a Rails project that uses UUIDs, through the uuid-ossp
extension. 我正在通过uuid-ossp
扩展与使用UUID的Rails项目一起工作。
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: 但是,要解决此问题,我需要手动操作并设置扩展,以便每个数据库的postgres超级用户启用该扩展:
-- 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. 我不会给我的用户或Rails项目用户任何我的数据库的超级用户特权-这似乎不是一个好习惯。 So how am I supposed to do this? 那我应该怎么做呢?
Note: this question's accepted answer doesn't answer the larger question in the title . 注意: 该问题的可接受答案不能回答标题中较大的问题 。
Apparently https://github.com/dimitri/pgextwlist will allow you to whitelist extensions without having to grant superuser privileges. 显然, https://github.com/dimitri/pgextwlist允许您将扩展列入白名单,而无需授予超级用户特权。
Found as an answer to Why can only a superuser CREATE EXTENSION hstore, but not on Heroku? 被发现为为什么只有超级用户才能创建hstore而不在Heroku上创建cstore的答案 。
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. 如果您无法通过标准迁移过程,那么最好的方法可能是在template1中启用扩展,这样扩展就存在于您创建的每个新数据库中。 Just remember if restoring a backup that used pg_dump to copy template0 rather than the default of template1. 只要记住是否还原使用pg_dump来复制template0而不是默认template1的备份即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.