简体   繁体   English

在Rails模式中启用UUID的最简单的最小特权方法是什么?

[英]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.

相关问题 在rails中使用小胡子视图模板的最简单方法是什么? - What's the simplest way to use mustache view templates in rails? 在Rails中将:pluck或:collect结果转换为字符串数组的最简单方法是什么? - What is simplest way to convert :pluck or :collect results to array of strings in Rails? 使一组方法可用于多个Rails应用程序的最简单方法是什么 - What is the simplest way to make a group of methods available to several Rails applications Gmaps4rails:通过AJAX添加标记后启用集群的正确方法是什么? - Gmaps4rails: What's the proper way to enable clustering after adding markers via AJAX? Rails 3.2,将关联/查找关联到属于另一个模式的旧表的最佳方法是什么? - Rails 3.2, what's the best way to associate/lookup to a legacy table belonging to another schema? 在elasticsearch中处理不是最简单的方法是什么? - what is simplest way to handle not in elasticsearch? 在Rails中对字符串字段的一部分进行SQL查询的最简单方法是什么? - What is the simplest way to order results from a SQL query on part of a string field in Rails? Rails3中的UUID - UUIDs in Rails3 存储在CVS中并发往Linux服务器的Rails应用程序最简单的部署/回滚方案是什么? - What's the simplest deploy/rollback scheme for a Rails app stored in CVS and destined for a Linux server? rails脚手架形式,添加字段的最简单方法? - rails scaffold form, simplest way of adding a field?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM